Skip to content
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

--follow-imports does not have an effect on following stub files #17298

Closed
ahyatt-continua opened this issue May 29, 2024 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@ahyatt-continua
Copy link

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:

mypy --follow-imports=silent --explicit-package-bases velo/velo.py

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
  • Python version used: 3.12
@ahyatt-continua ahyatt-continua added the bug mypy got something wrong label May 29, 2024
@hauntsaninja
Copy link
Collaborator

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.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants