-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Not finding attributes within __init__ modules when nested under a namespace package #5854
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
Comments
What exactly is the form of the relative imports you have, and what exactly is the error? |
Ok, my apologizes, I went through and tested to make sure I can exactly reproduce the error in a simplified environment. I've committed a simple example of code here: https://github.com/basicdays/mypy_test To reproduce, I've been running
I wanted to narrow down exactly what causes the error. It seems mypy is not picking up any module exports within It also currently seems to work if I reference a re-export from another module that is not the Just to clarify my first comment on this issue thread, not having |
Also just to add, if I add a stubbed |
I'm running into the same problem, although with a little bit different setup:
I have some problems even figuring out how to run mypy in such monorepo setup. I ended up with something that should work:
but I end up with the following error:
mypy 0.641 |
@basicdays Then you can run |
@basicdays I started working on namespace packages support. I'll contribute this to mypy when it's in better shape, but currently it should work for your setup. Make sure that your namespace package is in python path and you'll be able to run |
@rafales Awesome! I'll have to try that out and see what happens when I get the opportunity to. |
It looks like I'm currently running into this issue. @rafales I already have an empty py.typed inside my sub-package, nested under a namespace-package. Was/is there any resolution to this issue? I'm happy to provide more information regarding my particular setup, if need be. |
…e package When used with --namespace-packages, a directory containing no __init__.pyi file was previously added as a candidate to near_misses even if it contains a __init__.py file. This logic is doesn't seem sensible, particularly as the this directory was then chosen as the result instead of __init__.py inside the directory. Add a number of "unit tests" to verify FindModuleCache.find_module() using a sample directory structure under `test-data/packages` as well. This should cure python#5854.
…ckage When used with --namespace-packages, a directory containing no __init__.pyi was previously added as a candidate to near_misses even if it contained a __init__.py. This logic doesn't seem sensible, particularly as this directory was then chosen as the result of find_module() instead of the __init__.py inside the directory. This should cure python#5854.
We're running into the same issue and had a look. It seems like a simple bug in the I tried @rafales test at https://github.com/basicdays/mypy_test and it works correctly after the fix. |
Bug
0.641
Do you see the same issue after installing mypy from Git master?
I haven't tried the master branch yet, I certainly can if folks would like me to.
Currently I have a structure similar to this:
Let's also say I have some relative imports in
namespace_package.package1.__init__
that imports frommoduleA
.If I don't have any mypy settings, and run
mypy namespace_package
, things seem to work fine. If I addnamespace_packages = True
tosetup.cfg
, then it seems all the imports that were done innamespace_package.package1.__init__.py
seem to fail.I figured if I attempt to instead do
mypy -p namespace_package
, that mypy might be able to correctly figure out the relative imports, but I seem to be getting a message that its can't find the packagenamespace_package
. Same message if I trymypy -p namespace_package.package2
. I see this is referenced in issue #5759. I'm guessing these two might be related?I think I'm also finding that having
[mypy-namespace-package.*]
insetup.cfg
isn't having much of an effect when I'm not usingnamespace_packages = True
. I could probably report this one in a separate issue if folks would like me to.The text was updated successfully, but these errors were encountered: