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

from .x import y causes "Name already defined" for x #3735

Open
douglas-treadwell opened this issue Jul 18, 2017 · 3 comments
Open

from .x import y causes "Name already defined" for x #3735

douglas-treadwell opened this issue Jul 18, 2017 · 3 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal

Comments

@douglas-treadwell
Copy link

I believe this is different than #2135.

In this case, if I have a star import like...

#a.py
import * from b
import * from c

#b.py
from .x import y

#c.py
from .x import z

I get a "Name 'x' is already defined" error.

But the name x is not exported by b or c.

@ilevkivskyi
Copy link
Member

Python runtime semantics is such that from .x import y leads to adding a name x to the parent module namespace, and mypy follows this semantics. But then there is a whole bunch of issues when "redefining" modules, see #1297. This particular one however, seems to be easier to solve, since we import twice exactly the same module, and normally mypy allows this.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels Jul 18, 2017
@thomascellerier
Copy link

I got hit by this exact same bug, had to resort to import x instead of from x import y to make mypy happy (using mypy 0.590).

@JukkaL JukkaL added the false-positive mypy gave an error on correct code label May 19, 2018
@NeilGirdhar
Copy link
Contributor

I'm getting the reverse of this: https://github.com/NeilGirdhar/tikzify/blob/master/tikzify/__init__.py gives

tikzify/__init__.py:5: error: Name "foundation" is not defined
tikzify/__init__.py:6: error: Name "function_graph" is not defined
tikzify/__init__.py:7: error: Name "node_graph" is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal
Projects
None yet
Development

No branches or pull requests

5 participants