<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">--- On <b>Tue, 10/19/10, Chris Kaynor <i><ckaynor@zindagigames.com></i></b> wrote:<blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><div id="yiv815341417"><div class="yiv815341417gmail_quote"><blockquote class="yiv815341417gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
This is a proposal (pre-PEP?) for an enhanced reloading mechanism especially designed for iterative development:<br>
<br>
<a rel="nofollow" target="_blank" href="https://docs.google.com/document/pub?id=1GeVVC0pXTz1O6cK5mo-EaOJFqrL3PErO4okmHBlTeuw">https://docs.google.com/document/pub?id=1GeVVC0pXTz1O6cK5mo-EaOJFqrL3PErO4okmHBlTeuw</a><br>
<br>
The basic plan is to use the existing cycle-detecting GC to remap references from objects in the old module to equivalent objects in the new module.<br></blockquote><div><br></div><div>What happens if you change the __init__ or __new__ methods of an object or if you change a class's metaclass? It seems like those types of changes would be impossible to propagate to existing objects, and without propagating them any changes to existing objects may (are likely?) to break the object.</div></div></div></blockquote>Yes, this is a limitation of the approach.  More generally, any logic that has already run<div>and would execute differently with the reloaded module has the potential to break things.<div><br></div><div>Even with this limitation I think the approach is still valuable.  I spend far less time modifying</div><div>__new__ methods and metaclasses than I spend changing the implementation and API of</div><div>other class- and module-level
 methods.</div><div><br></div><div>The issue of old instances not having members that are added in a new __init__ is</div><div>problematic, but there are several workarounds such as temporarily wrapping the new</div><div>member in a property, or potentially the @reloadable decorator alluded to in the doc.</div></div></td></tr></table><br>