bpo-20490: Improve circular import error messaging#15308
Conversation
|
This is largely based on the work in https://bugs.python.org/issue33237 by @serhiy-storchaka #6398 |
demo$ tail -n999 a/*.py
==> a/b.py <==
from a.c import d
e = 1
==> a/c.py <==
from a.b import e
d = 1
==> a/__init__.py <==before$ python3.8 -c 'import a.b'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/x/a/b.py", line 1, in <module>
from a.c import d
File "/tmp/x/a/c.py", line 1, in <module>
from a.b import e
ImportError: cannot import name 'e' from 'a.b' (/tmp/x/a/b.py)after$ ~/workspace/cpython/python -c 'import a.b'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/x/a/b.py", line 1, in <module>
from a.c import d
File "/tmp/x/a/c.py", line 1, in <module>
from a.b import e
ImportError: cannot import name 'e' from 'a.b' (partially initialized module -- most likely due to a circular import) (/tmp/x/a/b.py) |
|
Thanks for working on this @asottile ! If this old idea will come true, that'd be cool. |
3d72f86 to
550209c
Compare
d56ddb9 to
e7b41f9
Compare
5d18cf9 to
efacf0f
Compare
|
(I'm rebasing to presumably fix the CI failure -- it doesn't seem related to my change, but I've been surprised before by macos 😆) |
efacf0f to
6ac3cf1
Compare
6ac3cf1 to
5feaa0c
Compare
|
Sorry @asottile and @zooba, I had trouble checking out the |
|
GH-15791 is a backport of this pull request to the 3.8 branch. |
|
This pull request introduced a reference leak: This is being tracked in: https://bugs.python.org/issue38090 |
https://bugs.python.org/issue20490