[issue992389] attribute error due to circular import

Nick Coghlan report at bugs.python.org
Tue Dec 17 14:47:35 CET 2013


Nick Coghlan added the comment:

I'm reopening this, since PEP 451 opens up new options for dealing with it (at least for loaders that export the PEP 451 APIs rather than only the legacy loader API, which now includes all the standard loaders other than the ones for builtins and extension modules)

The attached patch doesn't have an automated test and is quite rough around the edges (as the additional check for the parent being in sys.modules confuses a couple of the importlib tests), but it proves the concept by making the following work:

[ncoghlan at lancre py3k]$ cd ../play
[ncoghlan at lancre play]$ mkdir issue992389
[ncoghlan at lancre play]$ cat > issue992389/mod.py
from . import mod
print("Success!")
[ncoghlan at lancre play]$ python3 -c "import issue992389.mod"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "./issue992389/mod.py", line 1, in <module>
    from . import mod
ImportError: cannot import name mod
[ncoghlan at lancre play]$ ../py3k/python -c "import issue992389.mod"
Success!

----------
keywords: +patch
nosy: +larry
resolution: duplicate -> 
status: closed -> open
superseder: Modify IMPORT_FROM to fallback on sys.modules -> 
versions: +Python 3.4 -Python 3.3
Added file: http://bugs.python.org/file33177/issue992389_set_parent_module_attribute.diff

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


More information about the Python-bugs-list mailing list