re-importing modules

Steven D'Aprano steve at REMOVEME.cybersource.com.au
Tue May 1 00:17:30 EDT 2007


On Tue, 01 May 2007 00:32:20 +0000, John Nagle wrote:

> kyosohma at gmail.com wrote:
> 
>>>In addition to the warning that reload() does not recursively reload
>>>modules that the reloaded module depends on, be warned that reloading a
>>>module does not magically affect any functions or objects from the old
>>>version that you may be holding on to.
> 
>     Maybe reloading modules should be deprecated.  The semantics
> are awful, and it interferes with higher-performance implementations.


I'd hate for reload to disappear, it is great for interactive
development/debugging, at least under some circumstances. (If you have
complex and tangled class hierarchies, it might not be powerful enough.)

As for the semantics being awful, I disagree. reload() does exactly
what it claims to do, no more, no less. I wouldn't expect reload(module1)
to reload modules 2 through 5 just because they were imported by module1.
If I wanted them reloaded, I'd say so.

I'll admit to being puzzled for about five minutes the first time I found
my objects' behaviour wasn't being updated when I did a reload, but it
didn't take me long to slap myself in the head. Of course not -- if the
old objects are still around, they'll keep their old behaviour. That's
kind of an inconvenience, but unavoidable. I certainly DON'T want Python
to magically change objects (apart from module objects themselves) on a
reload.

Maybe reload() should be pulled out of the core Python language and turned
into an optional function. If (if!) Jython doesn't do interactive
development, then it doesn't need reload(); CPython, which does, does.



-- 
Steven D'Aprano 




More information about the Python-list mailing list