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

Namespace packages and __init__ imports #9716

Open
hauntsaninja opened this issue Nov 12, 2020 · 2 comments
Open

Namespace packages and __init__ imports #9716

hauntsaninja opened this issue Nov 12, 2020 · 2 comments
Labels
bug mypy got something wrong

Comments

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 12, 2020

--namespace-packages runs into an issue if we import from __init__.py explicitly.

For instance, given:

.
└── proj
    ├── __init__.py
    └── a.py

$ cat proj/__init__.py 
x: int

$ cat proj/a.py       
from .__init__ import x

$ cat proj/b.py
from proj.__init__ import x

running mypy will result in:

$ mypy proj --namespace-packages
proj/__init__.py: error: Source file found twice under different module names: 'proj' and 'proj.__init__'

This issue comes up at least twice in mypy_primer's corpus.

This is correct in that you do get two entries in sys.modules, but undesirable for this to block type checking

@hauntsaninja hauntsaninja added the bug mypy got something wrong label Nov 12, 2020
@JukkaL
Copy link
Collaborator

JukkaL commented Nov 12, 2020

Wow, I didn't even know that from .__init__ import ... is a thing. If it works at runtime and does something useful, we should probably try to support it.

@hauntsaninja
Copy link
Collaborator Author

hauntsaninja commented Nov 12, 2020

Yeah, I wouldn't really care about it if not for the fact that "Source file found twice under different module names" is a blocking error and in this case it's really hard to figure out what's causing it. So kind of painful in the context of #9636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants