You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug Report
If you have a library that creates a namespace package (say ns_package) with a regular type-hinted package inside it (say reg_package), and you import the regular package as from ns_package import reg_package, mypy sometimes gives the following error:
script.py:1: error: Skipping analyzing 'ns_package': found module but no type hints or library stubs
script.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
The error only shows up intermittently. More details below.
Create venv, activate and install the lib and mypy: python3.8 -m venv .venv; . .venv/bin/activate; python3.8 -m pip install -e ./lib/ mypy
Run mypy against script.py with python3.8 -m mypy -p script
Expected Behavior
Mypy should report no errors since the library has a py.typed file and type annotations.
Actual Behavior
Mypy's result changes with every run. Sometimes no error is reported. Sometimes the following error is reported:
script.py:1: error: Skipping analyzing 'ns_package': found module but no type hints or library stubs
script.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
From what I can tell, the error is always reported in every other run, consistently. Meaning if I run mypy twice in a row, one of them always fails and one of them always succeeds. This seems to suggest that mypy somehow maintains state from one run to the next?
Couple of points to note:
If the import statement is changed to import ns_package.reg_package as reg_package or from ns_package.reg_package import SOMETHING, the error is gone.
Adding the --namespace-packages CLI flag doesn't change the result.
Whether the lib is installed as an editable package doesnt change the result.
Whether its installed from local dir or PyPi doesn't change the result.
If ns_package is just a directory in the cwd instead of an installed package, and the --namespace-packages CLI flag is passed, the error is gone.
Your Environment
Mypy version used: 0.800
Mypy command-line flags: -p script
Mypy configuration options from mypy.ini (and other config files): None
Python version used: 3.8.6
Operating system and version: Red Hat Enterprise Linux Server 7.9 (Maipo)
The text was updated successfully, but these errors were encountered:
Thanks for reporting, I think this is #9852 (and the other issues linked there). Pretty unfortunate, but you could use --no-incremental as a workaround.
@hauntsaninja Ahh yes. That seems to be the same issue. Sorry about the dup. I was searching around for issues relating to "namespace packages", so I didn't find the linked issue, but now I see it happens even if the top package isn't a namespace package. --no-incremental does fix the problem. Unfortunately it slows down mypy quite a bit if running repeatedly, but it's not unreasonable. 👍
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
If you have a library that creates a namespace package (say
ns_package
) with a regular type-hinted package inside it (sayreg_package
), and you import the regular package asfrom ns_package import reg_package
, mypy sometimes gives the following error:The error only shows up intermittently. More details below.
To Reproduce
with content
python3.8 -m venv .venv; . .venv/bin/activate; python3.8 -m pip install -e ./lib/ mypy
script.py
withpython3.8 -m mypy -p script
Expected Behavior
Mypy should report no errors since the library has a
py.typed
file and type annotations.Actual Behavior
Mypy's result changes with every run. Sometimes no error is reported. Sometimes the following error is reported:
From what I can tell, the error is always reported in every other run, consistently. Meaning if I run mypy twice in a row, one of them always fails and one of them always succeeds. This seems to suggest that mypy somehow maintains state from one run to the next?
Couple of points to note:
import ns_package.reg_package as reg_package
orfrom ns_package.reg_package import SOMETHING
, the error is gone.--namespace-packages
CLI flag doesn't change the result.ns_package
is just a directory in the cwd instead of an installed package, and the--namespace-packages
CLI flag is passed, the error is gone.Your Environment
-p script
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: