The documentation states the --follow-imports=skip or --follow-imports=silent will suppress problems from imports. But this doesn't apply to pyi files, for reasons that aren't clear to me, and certainly make it impossible for us to use mypy. Our setup is that we use mypy with the pants build system, and are using protobufs. We generate stubs from the protobufs, which, when pants run, as colocated with the source files. However, try as I might, I cannot ever get a clean mypy run because the protobuf pyi files have issues that we cannot control, and do not care about.
velo/velo_admitter_pb2_grpc.pyi:8: error: Skipping analyzing "grpc": module is installed, but missing library stubs or py.typed marker [import-untyped]
velo/velo_admitter_pb2_grpc.pyi:9: error: Skipping analyzing "grpc.aio": module is installed, but missing library stubs or py.typed marker [import-untyped]
velo/velo_admitter_pb2_grpc.pyi:9: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
As you can see, I'm really only expecting errors on velo.py here. I believe it is an error to get errors about anything else.
To Reproduce
#!/bin/bash
# Run this from an empty directory you can delete later.
cat > repro.py <<EOF
import importlib
EOF
cat > importlib.pyi <<EOF
import nonexistent_module
EOF
mypy --follow-imports=silent repro.py
Expected Behavior
No errors from pyi files should be shown when --follow-imports=silent (or skip)
Actual Behavior
Errors from pyi files are shown when --follow-imports=silent (or skip)
Your Environment
Mypy version used: 1.10
Mypy command-line flags: See above
Mypy configuration options from mypy.ini (and other config files): None
Use a per-module glob config with follow_imports and follow_imports_for_stubs. Or change your codegen to add # mypy: ignore-errors at the top of the file.
Bug Report
The documentation states the --follow-imports=skip or --follow-imports=silent will suppress problems from imports. But this doesn't apply to
pyi
files, for reasons that aren't clear to me, and certainly make it impossible for us to use mypy. Our setup is that we use mypy with the pants build system, and are using protobufs. We generate stubs from the protobufs, which, when pants run, as colocated with the source files. However, try as I might, I cannot ever get a clean mypy run because the protobuf pyi files have issues that we cannot control, and do not care about.A real-life example:
As you can see, I'm really only expecting errors on
velo.py
here. I believe it is an error to get errors about anything else.To Reproduce
Expected Behavior
No errors from pyi files should be shown when
--follow-imports=silent
(orskip
)Actual Behavior
Errors from pyi files are shown when
--follow-imports=silent
(orskip
)Your Environment
mypy.ini
(and other config files): None