Title: Improved Type Interop with CLR by eirannejad · Pull Request #2055 · pythonnet/pythonnet · GitHub
Open Graph Title: Improved Type Interop with CLR by eirannejad · Pull Request #2055 · pythonnet/pythonnet
X Title: Improved Type Interop with CLR by eirannejad · Pull Request #2055 · pythonnet/pythonnet
Description: What does this implement/fix? Explain your changes. This PR addresses these issues: Current pythonnet does not allow subclassing from CLR Abstract classes Running python script with types containing __namespace__, more than once, would throw Type Exists exception Calling super().VirtualMethod() inside a python-derived virtual method, would result in an infinite loop Due to the nature of the changes, this is a single PR instead of multiple smaller ones. After PR merge: Python types can derive from CLR abstract classes. As before, abstract methods that are not implemented on the python type, will dynamically throw NotImplemented exception. Specifying __namespace__ is not required to created a ClassDerived anymore. All python derived classes are now represented by ClassDerived in managed memory. ClassDerived now caches generated types based on namespace, type name, and chain of base classes. This avoids regenerating types or throwing Type Already Exists exceptions. A new format for generated type names include full name of base class and interfaces in the typename. The naming format still ends in the python type name to be backward compatible and passes the unit tests Example: Full name of derived clr type for python type named SubClass, deriving from BaseClass and implementing BaseInterface1 and BaseInterface2: Python.Runtime.Dynamic.BaseClass__BaseInterface1__BaseInterface2__main__SubClass Support for one base class and multiple interfaces (Merged some ideas and code from #2028 - Potential merge conflicts) Derived class can call chosen constructors using super().__init__() pattern. class SubClass(BaseClassA): def __init__(self, v): super().__init__(v) Derived class can call base virtual methods using super().method() pattern. class SubClass(BaseClassA): def DoWorkWith(self, value): r = super().DoWorkWith(value) + 10 return r Improved virtual method and getter/setter routing. Custom attributes (OriginalMethod and RedirectedMethod) are now used to mark the original and redirected virtual methods. The method name format for OriginalMethod is changed to $"_BASEVIRTUAL__{name}" so it can handle calling original methods on base classes that does not match the name of current class. Previously this was not working. Other misc refactoring and improvements. No change in behavior. Does this close any currently open issues? Potentially (no tests have been done to ensure these issues are resolved) #1945 #1107 #1787 Any other comments? ... Checklist Check all those that are applicable and complete. Make sure to include one or more tests for your change If an enhancement PR, please create docs and at best an example Ensure you have signed the .NET Foundation CLA Add yourself to AUTHORS Updated the CHANGELOG
Open Graph Description: What does this implement/fix? Explain your changes. This PR addresses these issues: Current pythonnet does not allow subclassing from CLR Abstract classes Running python script with types containi...
X Description: What does this implement/fix? Explain your changes. This PR addresses these issues: Current pythonnet does not allow subclassing from CLR Abstract classes Running python script with types containi...
Opengraph URL: https://github.com/pythonnet/pythonnet/pull/2055
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4ad21be6-9fdf-be45-2a3b-5b7988a1c41f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9124:2A625F:8292E3:B7C226:6970B25B |
| html-safe-nonce | 06a6b74da7023ec2e19338952547dcac6a686a7249ff31b473ef6b4cf07e02d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTI0OjJBNjI1Rjo4MjkyRTM6QjdDMjI2OjY5NzBCMjVCIiwidmlzaXRvcl9pZCI6IjI4MTI1NTU5NDY4MjUzOTY4MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 98eab51c62d90630b97fe07e420ef6ed1f88e11632c84c76041a70725f57e464 |
| hovercard-subject-tag | pull_request:1171397635 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/pythonnet/pythonnet/pull/2055/files |
| twitter:image | https://avatars.githubusercontent.com/u/8197916?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/8197916?s=400&v=4 |
| og:image:alt | What does this implement/fix? Explain your changes. This PR addresses these issues: Current pythonnet does not allow subclassing from CLR Abstract classes Running python script with types containi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8e0be80373b724b033cdf8a7b1f78bf5fb6a5d7a2182a9a403aa30894606e390 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/pythonnet/pythonnet git https://github.com/pythonnet/pythonnet.git |
| octolytics-dimension-user_id | 6050430 |
| octolytics-dimension-user_login | pythonnet |
| octolytics-dimension-repository_id | 14748123 |
| octolytics-dimension-repository_nwo | pythonnet/pythonnet |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 14748123 |
| octolytics-dimension-repository_network_root_nwo | pythonnet/pythonnet |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b8714db0002cf78dc2d2566571807e404d6cb817 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width