-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Importing types from namespace packages emits false positives without from ... import ...
#5758
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.
8000By 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
Comments
from ... import ...
from ... import ...
Yup, I can repro this. There must be a corner case that I don't handle correctly yet. |
Can you try with #5762? |
I tested #5762 locally at it looks like it fixes the first part of this issue, using When the package is installed, and the current working directory does not contain the package source directory, I get the same false positive error with or without Too be clear, I get the same error when the package is installed with a file structure like this
|
So this seems specific to when it's installed. Could you make those files available as a throwaway GitHub repo so I can test with it? (I'm too lazy to try and copy/paste the entire setup from your initial message.) |
I made https://github.com/macbeth322/mypy-namespace-bug-repro for reproducing the issue. I also noticed that if you do I was looking through the code and I believe it may be related to https://github.com/python/mypy/blob/master/mypy/build.py#L577 and the fact that when you do |
Thanks for making the repro! I'm still banging my head against the wall but you're definitely right that it's got something to do with the ancestors. Unfortunately I don't think it's as simple as dropping that code (or even dropping it when the ancestor is a toplevel namespace), because later references to e.g. |
Hey, sorry for commenting on this quite old issue. It looks like I hit the same issue but with mypy 0.920. Having an import like Should I open a new issue for this? fin swimmer |
This patch keeps a scoped ignore of the extension itself since MyPy doesn't like namespace packages somehow and it needs to be investigated further [[1]]. [1]: python/mypy#5758
Looks like there's another corner case: namespace packages in projects with src layout. I've got |
Importing type hints from namespace packages only works when using the
from ... import ...
form.Using the
--namespace-packages
flag works properly when thetypedpkg_namespace-alpha
is not installed butmypy
is executed from the directory containing the package contents (as expected) but only for imports using thefrom ... import ...
style.import ...
does not work as expected. Likewise the same is true without the--namespace-packages
flag iftypedpkg_namespace-alpha
is installed.Specifically, the type hints are correctly imported but a false positive error message is still emitted of
Cannot find module named 'typedpkg_namespace'
.Repro steps
setup.py
typedpkg_namespace/alpha/alpha_module.py
from_imp.py
not_from_imp.py
typedpkg_namespace/alpha/__init__.py
andtypedpkg_namespace/alpha/py.typed
are emptyRepro Example
--namespace-packages
The text was updated successfully, but these errors were encountered: