On 9/29/07, Terry Reedy <tjreedy at udel.edu> wrote:
>> "Joseph Maurer" <clarkksv at yahoo.com> wrote in
> message news:844399.5421.qm at web58901.mail.re1.yahoo.com...> | I'd like to see the reload feature of Python enhanced so it can replace
> the methods for existing class instances, references to methods, and
> references to functions.
>> I think would we could get farther by restricting concern to replacing
> class attributes so that existing class instances would use their new
> definitions.
>> As I understand, the problem is this. After somemod is imported, 'import
> somemod' simply binds 'somemod' to the existing module object, while
> 'reload somemod' replaces the module object with a new object with all new
> contents, while references to objects within the old module object remain
> as are.
>
Actually, the way reload works is that it takes the module object from
sys.modules, and then re-initializes mod.__dict__ (this is why import
loaders must use any pre-existing module's __dict__ when loading). So
the module object itself is not replaced, it's just that it's __dict__
is mutated in-place.
-Brett