Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improved Type Interop with CLR#2055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
eirannejad wants to merge4 commits intopythonnet:masterfrommcneel:pr/newtypes

Conversation

eirannejad
Copy link
Contributor

@eirannejadeirannejad commentedDec 19, 2022
edited
Loading

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 throwType Exists exception
  • Callingsuper().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 throwNotImplemented exception.
  • Specifying__namespace__ is not required to created aClassDerived anymore. All python derived classes are now represented byClassDerived in managed memory.
  • ClassDerived now caches generated types based on namespace, type name, and chain of base classes. This avoids regenerating types or throwingType 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 namedSubClass, deriving fromBaseClass and implementingBaseInterface1 andBaseInterface2:
      Python.Runtime.Dynamic.BaseClass__BaseInterface1__BaseInterface2__main__SubClass
  • Support for one base class and multiple interfaces (Merged some ideas and code from1783 Implement Interface And Inherit Class #2028 - Potential merge conflicts)
  • Derived class can call chosen constructors usingsuper().__init__() pattern.
classSubClass(BaseClassA):def__init__(self,v):super().__init__(v)
  • Derived class can call base virtual methods usingsuper().method() pattern.
classSubClass(BaseClassA):defDoWorkWith(self,value):r=super().DoWorkWith(value)+10returnr
  • Improved virtual method and getter/setter routing. Custom attributes (OriginalMethod andRedirectedMethod) are now used to mark the original and redirected virtual methods. The method name format forOriginalMethod 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)

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 toAUTHORS
  • Updated theCHANGELOG

@eirannejadeirannejad marked this pull request as ready for reviewDecember 30, 2022 21:29
@eirannejad
Copy link
ContributorAuthor

Hello. Would anyone help me get some information on the error on these test fails? I can not run thedotnet test --runtime any-x64 --logger "console;verbosity=detailed" src/embed_tests/ test on my macOS machine as it throws lots of exceptions. Not sure what sort of environment it needs for testing locally

@filmor
Copy link
Member

If it fails to run locally, check the output. You are probably missing thePYTHONNET_PYDLL export. For me, it actually runs through on .NET Core but isextremely slow on Mono. That's why the respective CI jobs are timing out.

eirannejad reacted with thumbs up emoji

@lostmsu
Copy link
Member

lostmsu commentedJan 20, 2023
edited
Loading

Please, rebase on master if you are still willing to work on getting this PR in.

heartacker reacted with heart emoji

@eirannejad
Copy link
ContributorAuthor

@lostmsu Sure thing. Working on gettingmaster merged in

@mhsmith
Copy link

As part of this work, it would be good for Python subclassing of CLR types to be properly documented (#674 (comment)).

@eirannejad
Copy link
ContributorAuthor

Closing this PR as it is too old. I have merged the 3.0.3 master into my fork so I can create new updated PRs

@eirannejadeirannejad deleted the pr/newtypes branchDecember 20, 2023 22:13
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@eirannejad@filmor@lostmsu@mhsmith

[8]ページ先頭

©2009-2025 Movatter.jp