[Python-Dev] avoiding accidental shadowing of top-level libraries by the main module
Nick Coghlan
ncoghlan at gmail.com
Tue Jul 13 23:02:40 CEST 2010
On Wed, Jul 14, 2010 at 2:25 AM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
> Sure - there are trivial workarounds which is why I don't think there are
> *many* genuine use cases for a module reimporting itself with a different
> name.
My concerns aren't about a module reimporting itself directly, they're
about the case where a utility module is invoked as __main__ but is
also imported normally somewhere else in a program (e.g. pdb is
invoked as a top-level debugger, but is also imported directly for
some reason). Currently that works as a non-circular import and will
only cause hassles if there is top-level state in the affected module
that absolutely must be a singleton within a given application. Either
change (disallowing it completely as you suggest, or making it a
circular import, as I suggest) runs the risk of breaking code that
currently appears to work correctly.
Fred's point about the practice of changing __name__ in the main
module corrupting generated pickles is one I hadn't thought of before
though.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list