[issue12583] More detailed ImportError messages

Ram Rachum report at bugs.python.org
Wed Jul 20 09:29:55 CEST 2011


Ram Rachum <cool-rr at cool-rr.com> added the comment:

David, I don't think you've read my message carefully enough. I'm well aware that there are other ways in Python to import than the `import` statement. I'm proposing that it doesn't matter.

I asked, "isn't a circular import when you try to import a module `foo` while in a lower stack level you haven't finished importing `foo` yet?" If this is true, then you just need to have some kind of flag for each module saying "This module is currently being imported", which you set to `True` when you start importing and back to `False` when you finished importing. (It doesn't have to look exactly like this, it could be a context manager, or alternatively a centralized list of all module that are currently in the middle of an import.) Then when you have an `ImportError`, you check whether the module that the user tried to import has that flag raised, and if so notify him that it's probably a circular import problem.

Will that work?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12583>
_______________________________________


More information about the Python-bugs-list mailing list