On 03:30 pm, ncogh...@gmail.com wrote:


Fixing dual imports of the main module
--------------------------------------

Two simple changes are proposed to fix this problem:

1. In ``runpy``, modify the implementation of the ``-m`` switch handling to install the specified module in ``sys.modules`` under both its real name and the name ``__main__``. (Currently it is only installed as the latter) 2. When directly executing a module, install it in ``sys.modules`` under
  ``os.path.splitext(os.path.basename(__file__))[0]`` as well as under
  ``__main__``.

With the main module also stored under its "real" name, imports will pick it up from the ``sys.modules`` cache rather than reimporting it under a new name.

Something to consider here is how this will interact with Python files which are _not_ modules. I'm a little uneasy about having sys.modules["trial"] refer to the module defined by /usr/bin/trial.

Jean-Paul
_______________________________________________
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