Brain Dead Singleton

Robin Becker robin at SPAMREMOVEjessikat.fsnet.co.uk
Mon Jun 7 04:00:26 EDT 2004


Peter Hansen wrote:

......

>  > An easy fix involved restoring sys.modules to a pristine state
>  > before each document was generated.
> 
> I'd argue perhaps that "easy fix" should have read "hack", and
> that this doesn't fit my condition of "most sane situations".
> 

I think I would agree that this is a hack. Probably the correct fix 
would have been to packagize each document folder and the containing 
folder and then change all the imports to be absolute, but that would 
have meant changing far more lines of code and introducing packages 
which are not really packages.

> Would you say that this "fix" was really an elegant solution,
> or just a quick hack?  I don't think deleting things from
> sys.modules has defined, guaranteed behaviour, so I'm uncertain
> whether anyone should rely on it working.  I still think
> Colin's approach is a generally okay one.
> 
> -Peter

If sys.modules isn't intended to be a modifiable cache, perhaps we 
shouldn't be given access to it.

The docs for 2.3 say
"modules
     This is a dictionary that maps module names to modules which have 
already been loaded. This can be manipulated to force reloading of 
modules and other tricks. Note that removing a module from this 
dictionary is not the same as calling reload() on the corresponding 
module object."

So the Gods call call this a trick :)
-- 
Robin Becker



More information about the Python-list mailing list