[Python-Dev] -z, -i and -m, maybe bug in runpy?

Phillip J. Eby pje at telecommunity.com
Tue Jul 24 02:32:23 CEST 2007


While trying to get my -z replacement patch to work, I stumbled 
across a bug in the -m implementation (and in runpy).  It seems that 
when you run the code of a -m module, it is *not* run in the __main__ 
module namespace!

So even though __name__=='__main__', globals() is not 
sys.modules['__main__'].__dict__.  This seems wrong to me.  Does 
anybody know why runpy doesn't actually run the code in the target module?

One consequence of this is that the -i option is much less useful 
when you use -m, because the script's globals have disappeared before 
you get to the interpreter prompt.

At this point, I've successfully gotten a -z replacement patch, 
except that it inherits this apparent bug from -m, which for a while 
led me to believe my patch was broken (when in fact it works fine, 
apart from inheriting the -m behavior).

Does anybody know if this behavior is intended, and if so, why?  And 
what are the consequences of changing/fixing it?



More information about the Python-Dev mailing list