Description
-
Are you reporting a bug, or opening a feature request?
Reporting a bug -
Please insert below the code you are checking with mypy,
reproducer.zip
I'm somewhat new to mypy so I'm sorry if this is a user error. If nothing else, the error message produced doesn't seem particularly helpful in narrowing down what to do fix it (or what section I might look in in the documentation). This is an error from one of my projects that builds cleanly with mypy --strict as well as pylint, pyflakes, etc. (with a few suppressions where the different tools take different views over things). I've reduced it and suitably anonymized it. There is a kind of circular import taking place where I'm importing the MyX class in MyBase.py and the MyBase class from MyX.py but it's never previously caused any issues.
- What is the actual behavior/output?
(py3.6) e:\tmp\mypy-issue>python --version
Python 3.6.8
(py3.6) e:\tmp\mypy-issue>mypy --version
mypy 0.711
(py3.6) e:\tmp\mypy-issue>mypy --strict .
(py3.6) e:\tmp\mypy-issue>mypy --strict --new-semantic-analyzer .
outer\inner\MyDerived2.py:1: error: Name 'MyX' already defined (by an import)
outer\inner\MyDerived2.py:8: error: Invalid type "outer.MyX"
If I remove the explicit import of MyX from MyDerived2.py then it obviously fails with:
(py3.6) e:\tmp\mypy-issue>mypy --strict --new-semantic-analyzer .
outer\inner\MyDerived2.py:8: error: Name 'MyX' is not defined
- What is the behavior/output you expect?
No error with the new semantic analyzer (same as with the old semantic analyzer).
Activity
Cito commentedon Jul 13, 2019
This looks a bit similar to my issue #7172.
It seems to happen sometimes when an object is called like its containing module.
gregbedwell commentedon Jul 13, 2019
I'm guessing you meant issue #7203 ?
Cito commentedon Jul 13, 2019
Sorry, yes, #7203.
msullivan commentedon Jul 15, 2019
With 0.720 we instead get a
error: Module "outer.inner.MyBase" is not valid as a typemsullivan commentedon Jul 15, 2019
A minimized version:
This minimized code I think will actually fail at runtime, though, executing
from MyX import MyXThe original code is similarly dodgy, as one of the imports will actually get the submodule instead of the name.
Giving the classes the same name as modules is a worrisome practice, I think?
ilevkivskyi commentedon Jul 15, 2019
@msullivan
Taking into account minimized repros for both issues I wonder if this is a duplicate (or other way around) of #7203 (module function with the same name as containing module -> class with the same name as containing module)?
ilevkivskyi commentedon Aug 12, 2019
Closing as a duplicate of #7203