-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Add support for pkgutil-style namespace packages #9393
Comments
Checked with mypy 0.782, still no support for pkgutil-style namespace packages, even though the
|
Could it be limited work based on PR #5691? |
I've just found a way to adjust the source files configuration that makes mypy work with pkgutil-style namespace packages. In my
The trick, I guess, is that only one
Not sure however whether this is the expected configuration, or just a specific workaround for pkgutil-style namespace packages. Another observation: |
This limitation is still present in mypy 0.910 on Python 3.9 The trick with skipping the init file at root level and going for Another trick is to simply skip namespace packages altogether and just use underscores on normal packages instead, like |
+1 - Would be nice to have a proper fix for this. |
FWIW pkgutil-style namespacing is also necessary if trying to "merge" a namespace package with an existing package which contains code at this location, or when trying to make a sub-package of that a namespace package. |
For the info, I've recently updated my mypy configuration file with mypy v1.0.1
|
Python 2 is very dead, mypy is not going to gain support for pkgutil style namespaces. |
🚀 Feature
Add support for pkgutil-style namespace packages.
Pitch
In october 2018, PR #5691 brought support for PEP420 namespace packages (i.e. native namespace packages), which closed issue #1645.
However, the native PEP420 method only works for Python 3.
According to Python documentation, for Python 2/3 compatible code, the pkgutil-style remains the recommended way.
Let the following project structure, with PYTHONPATH and MYPYPATH pointing to the
src/
and 'tests/src/' directories:The
mynamespace
namespace is splitted in two directories, in order not to mix up the test code with the deliverable code in this project.Within both
src/mynamespace/__init__.py
andtests/src/mynamespace/__init__.py
, the following code implements the pkgutil-style namespace package:Python 2 and Python 3 execute this code correctly.
But, unfortunately, mypy (as of 0.770) generates a false 'Duplicate module named 'mynamespace'' error (same error as the former #1645 issue).
The text was updated successfully, but these errors were encountered: