Fix superreload in; enables updating code objects

Bug #237691 reported by Pauli Virtanen on 2008-06-05
Affects Status Importance Assigned to Milestone
Fix Committed
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()
>>> c.baz()
[edit and change baz and SomeClass.baz to print "ASD"]
>>> baz()
>>> c.baz()

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.

Pauli Virtanen (pauli-virtanen) wrote :
Changed in ipython:
assignee: nobody → villemvainio
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

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
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  Edit
Everyone can see this information.

Other bug subscribers