This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Show clear error message on circular import
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, Arfrever, brett.cannon, cool-RR, pablogsal, r.david.murray, steve.dower, yselivanov
Priority: normal Keywords: patch

Created on 2014-02-02 19:04 by cool-RR, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15308 merged Anthony Sottile, 2019-08-15 19:49
PR 15791 merged steve.dower, 2019-09-09 15:21
Messages (6)
msg210006 - (view) Author: Ram Rachum (cool-RR) * Date: 2014-02-02 19:04
If there's a circular import in my program, I don't want to see an error message, "Cannot import name 'foo'" and then say in my mind, "ah, I'm an experienced Python developer, I know that when Python says that it often means that there's a circular import problem." I want the error message to **say there's a circular import problem**, so (a) I won't have to remember this piece of trivia and (b) less experienced developers won't have to bang their heads on their desks trying to figure out why the import isn't working. 

Bonus points if the error message actually shows which module is trying to import a module that imports itself, so we'll know where to fix.
msg210153 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-02-03 18:32
It's not as simple as it sounds because failures from "from ... import ..." are triggered in the eval loop and not in import and without thinking it through I don't know if you could use the fine-grained import locks to inspect if something is in the middle of being imported or not that way.
msg351496 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-09-09 15:17
New changeset 65366bc8bdc4716ebc361e622590b45a6e5aef07 by Steve Dower (Anthony Sottile) in branch 'master':
bpo-20490: Improve circular import error message (GH-15308)
https://github.com/python/cpython/commit/65366bc8bdc4716ebc361e622590b45a6e5aef07
msg351505 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-09-09 15:48
Thanks for the patch, Anthony!
msg351529 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-09-09 16:45
New changeset 2d5594fac21a81a06f82c3605318dfa96e72398f by Steve Dower in branch '3.8':
bpo-20490: Improve circular import error message (GH-15308)
https://github.com/python/cpython/commit/2d5594fac21a81a06f82c3605318dfa96e72398f
msg351642 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-09-10 13:06
This PR introduced a reference leak tracked in:

https://bugs.python.org/issue38090
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64689
2019-09-10 13:06:52pablogsalsetnosy: + pablogsal
messages: + msg351642
2019-09-09 16:45:20steve.dowersetmessages: + msg351529
2019-09-09 15:48:07steve.dowersetstatus: open -> closed
resolution: fixed
messages: + msg351505

stage: patch review -> resolved
2019-09-09 15:21:00steve.dowersetpull_requests: + pull_request15444
2019-09-09 15:17:54steve.dowersetnosy: + steve.dower
messages: + msg351496
2019-08-15 20:02:08Anthony Sottilesetnosy: + Anthony Sottile

versions: + Python 3.8, Python 3.9, - Python 3.5
2019-08-15 19:49:46Anthony Sottilesetkeywords: + patch
stage: patch review
pull_requests: + pull_request15028
2014-02-03 19:33:00Arfreversetnosy: + Arfrever
2014-02-03 18:32:19brett.cannonsetmessages: + msg210153
2014-02-02 19:34:13r.david.murraysetnosy: + r.david.murray
2014-02-02 19:20:15yselivanovsetnosy: + brett.cannon
2014-02-02 19:20:07yselivanovsetnosy: + yselivanov
2014-02-02 19:04:48cool-RRcreate