Fix superreload in ipy_autoreload.py; enables updating code objects
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
IPython |
Fix Committed
|
Low
|
Ville M. Vainio |
Bug Description
Part of the functionality of 'superreload' (originally by Thomas Heller) used in
the ipy_autoreload extension was broken in the patch that I sent and got accepted.
The attached patch restores this functionality.
What this adds, is upgrading Python code objects of old function objects in the reloaded module.
This makes eg. the following to work:
>>> %autoreload 1
>>> %aimport foo
>>> from foo import baz, SomeClass
>>> c = SomeClass()
>>> baz()
"FOO"
>>> c.baz()
"FOO"
[edit foo.py and change baz and SomeClass.baz to print "ASD"]
>>> baz()
"ASD"
>>> c.baz()
"ASD"
Technically, this is implemented by collecting weakrefs to objects previously in
the module before reloading, then reloading the module, and finally going through
the list of existing references and replacing obj.func_code for those function objects
that have a new version in the reloaded module.
Changed in ipython: | |
assignee: | nobody → villemvainio |
Changed in ipython: | |
status: | In Progress → Fix Committed |
New patch that fixes some bugs:
- Catch and ignore TypeErrors raised on setting unsettable attributes
- Don't touch objects that were imported from other modules