[issue44717] Improve AttributeError on circular imports of submodules
Filipe Laíns
report at bugs.python.org
Thu Jul 22 20:51:19 EDT 2021
New submission from Filipe Laíns <lains at riseup.net>:
Consider the following
$ tree a
a
├── b
│ ├── c.py
│ └── __init__.py
└── __init__.py
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 `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.
----------
components: Interpreter Core
messages: 398021
nosy: FFY00, pablogsal
priority: normal
severity: normal
status: open
title: Improve AttributeError on circular imports of submodules
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44717>
_______________________________________
More information about the Python-bugs-list
mailing list