On 13/07/2010 14:00, Nick Coghlan wrote:
(Two different classes with the same name created - one from __main__ and
one from real_name.) Use cases for *genuinely* reimporting the same module
with different names (as different module objects rather than aliases) are
relatively rare, and the problem of modules *accidentally* reimporting
themselves not that rare.
That particular issue can be resolved by automatically doing the
shadowing at the sys.module level though (i.e. insert into sys.modules
under the real module name as well as __main__ for
runpy._run_module_as_main and just strip the directory and extension
details from __file__ to determine where to insert the second
reference for a directly executed script file).

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.

Michael

Making sure both __main__ and the corresponding importable name refers
to the same module object seems reasonable. Trying to special case
shadowing detection just because the shadowing module happens to also
be the main module seems ugly as hell :)

Cheers,
Nick.



--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of 
your employer, to release me from all obligations and waivers arising from any 
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, 
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and 
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your 
employer, its partners, licensors, agents and assigns, in perpetuity, without 
prejudice to my ongoing rights and privileges. You further represent that you 
have the authority to release me from any BOGUS AGREEMENTS on behalf of your 
employer.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to