[Python-Dev] towards a faster Python

Phillip J. Eby pje@telecommunity.com
Mon, 09 Jun 2003 16:18:57 -0400


At 03:02 PM 6/9/03 -0500, Skip Montanaro wrote:
>     Neil> It's possible to modify the module dict directly and bypass the
>     Neil> warning.  I'm not sure what to do about that. :-(
>
>Make the module dict read-only and some as-yet-to-be-determined time during
>import?  That is, upon initial import of a module the dict collecting names
>would be made writable, but once it's associated with a module object (or
>the import is completed), the dict would be flagged read-only or be
>transmogrified into a read-only dict subclass of dict().

You're forgetting about globals; functions have a func_globals reference to 
their globals dictionary, and if the function modifies any globals, it has 
to be writable.

In any case, I'm not sure what the use case is here for stopping all 
modifications of a module __dict__.  Presumably, if somebody writes to 
__dict__ in order to bypass the warning, they either know what they're 
doing or deserve what they get.  :)