[Python-ideas] ImportError raised for a circular import

Ivan Levkivskyi levkivskyi at gmail.com
Wed Jun 14 04:26:42 EDT 2017


On 14 June 2017 at 09:59, Paul Moore <p.f.moore at gmail.com> wrote:

> On 13 June 2017 at 23:36, Chris Angelico <rosuav at gmail.com> wrote:
> > On Wed, Jun 14, 2017 at 8:10 AM, Mahmoud Hashemi <mahmoud at hatnote.com>
> wrote:
> >> I didn't interpret the initial email as wanting an error on *all*
> circular
> >> imports. Merely those which are unresolvable. I've definitely helped
> people
> >> diagnose circular imports and wished there was an error that called
> that out
> >> programmatically, even if it's just a string admonition to check for
> >> circular imports, appended to the ImportError message.
> >
> > Oh! That could be interesting. How about a traceback in the import chain?
>
> I have a feeling that mypy might flag circular imports. I've not used
> mypy myself, but I just saw the output from a project where we enabled
> very basic use of mypy (no type hints at all, yet) and saw an error
> reported about a circular import. So with suitable configuration, mypy
> could help here (and may lead to other benefits if you want to use
> more of its capabilities).
>

Mypy doesn't always flag invalid circular imports, there is an old issue
about this,
see https://github.com/python/mypy/issues/61
But yes, one gets many other benefits like static type checking
(including checking the types of things imported in a circular manner).

--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170614/0a2c641e/attachment.html>


More information about the Python-ideas mailing list