[issue19211] from relative_module import seems to import wrong module

R. David Murray report at bugs.python.org
Wed Oct 9 20:28:19 CEST 2013


R. David Murray added the comment:

I believe that this is because once you execute the first line, 'a' exists as a name in the 'lib' namespace, so 'from . import a' sees that 'a' already exists, and does nothing.  The same import sequence in abc.py will put 'a' into the 'abc' namespace, but 'from . import a' will be looking in the 'lib' namespace, won't see an 'a', and will do the new import, overwriting the definition of 'a' in the 'abc' namespace as it does so.

The exact effects of imports inside __init__ is sometimes a bit non-intuitive.

----------
nosy: +r.david.murray

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19211>
_______________________________________


More information about the Python-bugs-list mailing list