Fix superreload in ipy_autoreload.py; enables updating code objects

Bug #237691 reported by Pauli Virtanen
2
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.

Revision history for this message
Pauli Virtanen (pauli-virtanen) wrote :
Changed in ipython:
assignee: nobody → villemvainio
Revision history for this message
Pauli Virtanen (pauli-virtanen) wrote :

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

Revision history for this message
Brian Granger (ellisonbg) wrote :

Please create a branch for this patch and post for review.

Changed in ipython:
importance: Undecided → Low
status: New → In Progress
Revision history for this message
Pauli Virtanen (pauli-virtanen) wrote :

I think the patch was applied in r1002 to trunk

Changed in ipython:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.