| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
This seems to be a patch for broken behaviour in Python. Removing it should solve pythonnet#495 (`__init__` called twice on construction).
Codecov Report
@@ Coverage Diff @@
## master #496 +/- ##
==========================================
- Coverage 76.41% 75.95% -0.47%
==========================================
Files 64 64
Lines 5572 5572
Branches 895 894 -1
==========================================
- Hits 4258 4232 -26
- Misses 1020 1044 +24
- Partials 294 296 +2
Continue to review full report at Codecov.
|
Sorry, something went wrong.
|
Don't merge this yet, apparently the example given by @rickardraysearch is not tested. When running his test: class X(System.Object):
__namespace__ = "PyTest"
def __init__(self, *args):
print("Running X constructor, args = {0}".format(args))
x = X(1,2)
one can see that without the tp_call implementation given here, __init__ is always called without parameters. I'll add the test and try to make it work. |
Sorry, something went wrong.
|
My very naive understanding of what is being done in pythonnet is as follows: Since there's no exact equivalence to a constructor in python indicating which base constructor to use (apart from calling one in __new__), pythonnet solves that by copying all base constructors to the subclass (AddConstructor in ClassDerivedObject.CreateDerivedType), but tries to run the python-defined __init__ with any remaining arguments from the constructor call (the eargs thingy in ConstructorBinder.InvokeRaw). That fails in this case, since InvokeRaw is called by the created CLR constructor, which has already lost the extra arguments. Wouldn't it make more sense to have a ClassDerived.tp_init method that calls __init__ with whatever arguments are passed there? I have a commit at rickardraysearch/pythonnet@ a06fc32 that does more or less that with some bugs. |
Sorry, something went wrong.
|
This is exactly what I was looking into right now :) |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This seems to be a patch for broken behaviour in Python. Removing it
should solve #495 (__init__ called twice on construction).
What does this implement/fix? Explain your changes.
#495
Does this close any currently open issues?
#495
Checklist
Check all those that are applicable and complete.