-
Notifications
You must be signed in to change notification settings - Fork 749
Constructor executed twice when overriding constructor in System.Object. #495
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Furthermore, if you add arguments to the constructor, the arguments are only passed the second time. class X(System.Object):
__namespace__ = "PyTest"
def __init__(self, *args):
print("Running X constructor, args = {0}".format(args))
x = X(1,2) produces the output
It seems that the first invocation is from the call in Is the error that somehow the call to |
Hmm, the comment says
Maybe this changed in Python? I'll have a look. |
This seems to be a patch for broken behaviour in Python. Removing it should solve pythonnet#495 (`__init__` called twice on construction).
This seems to be a patch for broken behaviour in Python. Removing it should solve pythonnet#495 (`__init__` called twice on construction).
* Add tests of subclassing with __namespace__ * Remove __init__ call from ClassDerived.InvokeCtor * Trying out __init__ * Cleanup * Add tests constructing python type from CLR and calling __init__ * Revert borked changelog update * Don't leak init reference * Rename tests * Remove unused internal Runtime.GetBoundArgTuple * Reenable skipped tests in test_subclass.py
Fixed by #503. |
* Add tests of subclassing with __namespace__ * Remove __init__ call from ClassDerived.InvokeCtor * Trying out __init__ * Cleanup * Add tests constructing python type from CLR and calling __init__ * Revert borked changelog update * Don't leak init reference * Rename tests * Remove unused internal Runtime.GetBoundArgTuple * Reenable skipped tests in test_subclass.py
Environment
Details
We are trying to create a subclass of System.Object (using namespace) and override the constructor.
For some reason, the conctructor is executed twice when an instance of the class is created. Below is an example that reproduces the problem.
The output is
The text was updated successfully, but these errors were encountered: