reloading modules and isinstance()

Diez B. Roggisch deets at nospam.web.de
Thu Dec 6 07:59:00 EST 2007


Jean-Paul Calderone schrieb:
> On Thu, 06 Dec 2007 12:21:01 +0100, "Diez B. Roggisch" 
> <deets at nospam.web.de> wrote:
>> Tlis schrieb:
>>> On 5 Dec, 13:18, Steven D'Aprano <st... at REMOVE-THIS-
>>> cybersource.com.au> wrote:
>>>> On Tue, 04 Dec 2007 15:41:48 +0100, Diez B. Roggisch wrote:
>>>>> You just discovered one reason why reload() is a bad idea and IMHO
>>>>> shouldn't be used at all - as tempting it might be.
>>>> I disagree -- I find reload() extremely useful for interactively 
>>>> testing
>>>> modules. But I would never dream of using it in production code!
>>>>
>>>> -- 
>>>> Steven.
>>>
>>> Please note, that I was using the 'Reload modules' functionality of
>>> the software system in use, rather than the reload() function
>>> directly. I admit, though, that in the background it just may call
>>> reload() ...
>>>
>>> With all the problems of the reload() function, I still hope, that
>>> there should be possible to write a safe module 'reloader', that would
>>> fix the references, as required (e.g. by changing the
>>> variable.__class__ references). This should be provided by every
>>> serious Python development environment.
>>
>> Wishful thinking. If I do
>>
>> foo = {}
>> foo['some_key'] = somemodule.SomeClass
>>
>> somewhere in my code, how do you suppose is reload(somemodule) to know
>> where in all the world I keep references to that class? Thus it would
>> essentially have to scan all references to anything, all list contents,
>> all class-properties, all everything. Which is not feasible.
> 
> Who says it isn't feasible?
> 
> http://twistedmatrix.com/trac/browser/trunk/twisted/python/rebuild.py

Nice try - for sure. But it seems to be geared towards special cases, 
not a general-purpose "now reloading really works" implementation.

Diez



More information about the Python-list mailing list