Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-20490: Improve circular import error messaging #15308

Merged
merged 1 commit into from
Sep 9, 2019

Conversation

asottile
Copy link
Contributor

@asottile asottile commented Aug 15, 2019

@asottile
Copy link
Contributor Author

This is largely based on the work in https://bugs.python.org/issue33237 by @serhiy-storchaka #6398

@asottile
Copy link
Contributor Author

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)

@cool-RR
Copy link
Contributor

cool-RR commented Aug 15, 2019

Thanks for working on this @asottile ! If this old idea will come true, that'd be cool.

@asottile asottile force-pushed the partially_initialized_bpo_20490 branch from 3d72f86 to 550209c Compare August 15, 2019 20:01
@asottile asottile force-pushed the partially_initialized_bpo_20490 branch 2 times, most recently from d56ddb9 to e7b41f9 Compare August 15, 2019 23:11
@asottile asottile force-pushed the partially_initialized_bpo_20490 branch 2 times, most recently from 5d18cf9 to efacf0f Compare August 21, 2019 22:41
@asottile
Copy link
Contributor Author

(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 😆)

@brettcannon brettcannon reopened this Aug 23, 2019
Python/ceval.c Outdated Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
@asottile asottile force-pushed the partially_initialized_bpo_20490 branch from efacf0f to 6ac3cf1 Compare August 31, 2019 23:44
Python/ceval.c Outdated Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
Python/ceval.c Outdated Show resolved Hide resolved
Lib/test/test_import/__init__.py Outdated Show resolved Hide resolved
@asottile asottile force-pushed the partially_initialized_bpo_20490 branch from 6ac3cf1 to 5feaa0c Compare September 1, 2019 00:46
@zooba zooba merged commit 65366bc into python:master Sep 9, 2019
@zooba zooba added the needs backport to 3.8 only security fixes label Sep 9, 2019
@miss-islington
Copy link
Contributor

Thanks @asottile for the PR, and @zooba for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @asottile and @zooba, I had trouble checking out the 3.8 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 65366bc8bdc4716ebc361e622590b45a6e5aef07 3.8

@bedevere-bot
Copy link

GH-15791 is a backport of this pull request to the 3.8 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.8 only security fixes label Sep 9, 2019
@asottile asottile deleted the partially_initialized_bpo_20490 branch September 9, 2019 15:22
@pablogsal
Copy link
Member

pablogsal commented Sep 10, 2019

This pull request introduced a reference leak:

https://buildbot.python.org/all/#/builders/1/builds/710

This is being tracked in:

https://bugs.python.org/issue38090

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.