| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@rickardraysearch, thanks! @vmuriart, @tonyroberts, @tiran, @ArvidJB and @brianlloyd, please review this. |
Sorry, something went wrong.
Codecov Report
@@ Coverage Diff @@
## master #503 +/- ##
==========================================
+ Coverage 76.41% 77.21% +0.79%
==========================================
Files 64 64
Lines 5572 5534 -38
Branches 895 887 -8
==========================================
+ Hits 4258 4273 +15
+ Misses 1020 975 -45
+ Partials 294 286 -8
Continue to review full report at Codecov.
|
Sorry, something went wrong.
| assert calls[0][0] == (1,2,3) | ||
| assert calls[0][1] == {"foo":"bar"} | ||
|
|
||
| def test_clr_subclass_without_init_args(): |
There was a problem hiding this comment.
please rename test_clr_subclass_init_without_args
Sorry, something went wrong.
| IntPtr type = Runtime.PyObject_TYPE(obj); | ||
| IntPtr init = Runtime._PyType_Lookup(type, py__init__); | ||
| Runtime.XDecref(py__init__); | ||
| var init = Runtime.PyObject_GetAttrString(obj, "__init__"); |
There was a problem hiding this comment.
You are leaking this reference.
Sorry, something went wrong.
There was a problem hiding this comment.
Oh. Should be fixed now.
Sorry, something went wrong.
|
Could you explain how and why this works? /edit: Never mind, got it :) |
Sorry, something went wrong.
|
I believe that what's happening is that MetaType.tp_call is calling __init__ on the class, just as PyType_Type does in type_call. It has access to all of the passed arguments, including those not available in the CLR constructor. Since the class' __init__ is called from there, there is no need to call it from ClassDerived.InvokeCtor. When constructing python objects from e.g. C#, the __init__ method would need to be called separately, since the CLR constructor only creates the object. If that should change, I believe we should have a look at actually calling __new__ for python types with __namespace__ and make those arguments match whatever is generated for the CLR constructors. |
Sorry, something went wrong.
|
From the commit history, it looks as if the call was added to invoke __init__ when instantiating python classes from managed code. The tests that @tonyroberts added then still work though, so hopefully this PR isn't breaking any existing major use cases by removing the call to __init__ when constructing python objects from managed code. By the way, there are two tests in test_subclass.py that are currently skipped with the comment FIXME: test randomly pass/fails. I have run them a couple of hundred times, both on macos and windows, with python 2.7 and 3.6, and not seen a single fail. Can I try reenabling them? They are both relevant to this PR. /edit: I reenabled them, and they worked on both Travis and Appveyor, at least this time. |
Sorry, something went wrong.
|
Thank you very much for your contribution. We'll have to see, whether this breaks compatibility for anyone, we probably should put a note into the changelog, documenting this change of behaviour. |
Sorry, something went wrong.
|
Yes, it definitely makes sense to put a good explanation in the changelog. Also, could we have a discussion on how to bring back that functionality and exposing additional arguments to the managed constructors? Maybe a new issue is the best place for that. Many thanks for merging this, by the way! It really makes a big difference for my chances of getting us to use pythonnet here. |
Sorry, something went wrong.
|
Feel free to open one :) |
Sorry, something went wrong.
* 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
| Back | FazBrowse Home | New Git URL |
What does this implement/fix? Explain your changes.
Remove the extraneous call to __init__ from ClassDerived.InvokeCtor.
Does this close any currently open issues?
#495
Any other comments?
This is a different shot at fixing #495 . @filmor has one at #496 but it fails a couple of tests. This one might have some bugs wrt XDecref in MetaType.tp_call still.
Checklist
Check all those that are applicable and complete.