allow type of already existing class instances to be updated#11644
allow type of already existing class instances to be updated#11644Carreau merged 5 commits intoipython:masterfrom Naikless:master
Conversation
|
Thanks for your contribution, and congrats, I know it is a sometime scary step ! I'll try to come back to review this as soon as possible, though I'm quite busy this week, so I can't promise. From a quick read that looks great, I just need to understand it, and find out how to fix the tests. Thanks ! |
|
Starting to look into this. |
There seem to have been some infinite recursion in the previous version of the code, so implement a more classical graph finding algorithm. This should still be properly tested
|
Would you mind having a look at this new version ? I proposed an alternative with less recursion, which appear to work on my machine. Test and docs are still needed though, and code need to be cleaned up. |
|
Hey ! Basic test seem to pass. Sounds like a good start. @daharn how familiar are you with git/github ? Will you manage to get my changes on your machine, and can take care of (some-of) the cleaning documenting ? Or do you need some extra guidance ? |
|
Thanks for looking into this! |
|
Thanks ! Much appreciated. |
… avoid infinite recursion. This should pass the already existing autoreload tests, however, new tests for this feature still need to be implemented.
|
Next attempt. I kind of stuck to my original recursion but tried to include your suggested checks to avoid revisiting of already browsed objects. This passes the tests and does a good job on updating all instance references in the user namespace (a notable exception are instances yielded from a generator. I don't know whether it would even be possible to update them). Let me know what you think and if you have an idea on how to add some tests for this feature in the autoreload tests. |
|
Thanks for this, I'll try to look at it soon. |
|
I'm still planning to have a look. Apologies for the delay |
|
No worries, we are all doing this in our spare time I guess. |
|
I wrote and push test for this functionality. You can run |
|
Well, took little over 3 month; so thanks for your patience; but that looks god to me; I removed one more debug statement and will wait for tests to pass then merge. I need to remember to update the what's new to give an example of the new possibility. |
|
Thanks for including this. Keep up the great work! |
|
Can you check #11849 for your use case ? I'm hoping this will still work properly and potentially be faster. |
|
I will as soon as I am able to. If this iterating through workspace turns out to be unsuited in general, a new (and arguably more elegant approach) would be to maintain a list of all objects for any custom module and add each object to it, when it is created. Maybe this could be done by messing with the definition of |
|
I think there might be a better way. Usually |
|
The %load_ext autoreload magic is very handy when I work in a dual development mode: Jupyter+IDE. |
I have tinkered with |
Not particularly; I was just conservative in case |
|
I gave it a try and it works quite well. Don't know if |
This is my first attempt in solving the problematic discussed in #11588. Although
%autoreloadupdates class attributes for reloaded modules "on the fly", thus providing these updated attributes also to previously instantiated objects of that class, these old objects remain of type "old class definition", meaning that they can't be pickled.(This is also my first open source contribution in general, so be gentle with me :) )
As you can see, this relies on identifying the execution frame from the stack that holds all user defined variables. My current search conditions were inspired by the definition of
%who_ls, but even though it worked for manual tests (creating a module with a class, creating an instance of that class, change the definition inside the module, compare type of already existing instance with new ones), I couldn't get it to work in the FakeShell environment of the tests in test_autoreload. So maybe there is a more general/fail proof possibility to find the user namespace?EDIT: The tests fail mainly because
FakeShelldoesn't have auser_ns. Adding an empty namespace lets the tests succeed, but the functionality is still lost.