You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve AttributeError on circular imports of submodules #88880
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2021-07-24.22:45:30.358>created_at=<Date2021-07-23.00:51:19.896>labels= ['interpreter-core', 'type-feature']
title='Improve AttributeError on circular imports of submodules'updated_at=<Date2021-07-25.01:27:23.066>user='https://github.com/FFY00'
a.b
$ python
Python 3.9.6 (default, Jun 30 2021, 10:22:16)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import a.b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/anubis/test/a/b/__init__.py", line 1, in <module>
import a.b.c
File "/home/anubis/test/a/b/c.py", line 3, in <module>
a.b
AttributeError: module 'a' has no attribute 'b'
This happens because even though the module a is initialized, the b attribute is not set due to the circular import. When a module is partially initialized, we get a more helpful error description hinting that we cannot access the attribute because the module is partially initialized, we could have something similar here.
New changeset 3eae8f2 by Pablo Galindo Salgado in branch 'main':
Revert "bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)" (GH-27331) 3eae8f2
Activity
FFY00 commentedon Jul 23, 2021
Consider the following
1 directory, 3 files
$ cat a/b/init.py
import a.b.c
$ cat a/b/c.py
import a.b
a.b $ python Python 3.9.6 (default, Jun 30 2021, 10:22:16) [GCC 11.1.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import a.b Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/anubis/test/a/b/__init__.py", line 1, in <module> import a.b.c File "/home/anubis/test/a/b/c.py", line 3, in <module> a.b AttributeError: module 'a' has no attribute 'b'This happens because even though the module
ais initialized, thebattribute is not set due to the circular import. When a module is partially initialized, we get a more helpful error description hinting that we cannot access the attribute because the module is partially initialized, we could have something similar here.ambv commentedon Jul 24, 2021
New changeset 8072a11 by Filipe Laíns in branch 'main':
bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)
8072a11
ambv commentedon Jul 24, 2021
Thanks a lot for your report and patch, Filipe! ✨ 🍰 ✨
pablogsal commentedon Jul 24, 2021
There is a buildbot failure after merging this PR:
https://buildbot.python.org/all/#/builders/464/builds/574
If is not fixed in 24 we will need to revert per our buildbot policy
pablogsal commentedon Jul 24, 2021
New changeset 3eae8f2 by Pablo Galindo Salgado in branch 'main':
Revert "bpo-44717: improve AttributeError on circular imports of submodules (GH-27299)" (GH-27331)
3eae8f2
pablogsal commentedon Jul 24, 2021
New changeset 0a8ae8a by Filipe Laíns in branch 'main':
bpo-44717: improve AttributeError on circular imports of submodules (GH-27338)
0a8ae8a