Skip to content

Imports in generated files aren't findable by mypy #681

@brandonchinn178

Description

@brandonchinn178

Maybe I'm not installing the tool right, but I'm getting type errors on the import statements that mypy-protobuf generates.

Repro steps:

  1. python3 -m venv venv
  2. venv/bin/pip install mypy types-protobuf
  3. Download https://github.com/nipunn1313/mypy-protobuf/blob/main/test/generated/mypy_protobuf/extensions_pb2.pyi
  4. venv/bin/mypy extensions_pb2.pyi
extensions_pb2.pyi:7: error: Cannot find implementation or library stub for module named "google"  [import-not-found]
extensions_pb2.pyi:7: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Related to python/mypy#16149

By itself, this doesn't really matter to us, since we ignore all errors in the generated _pb2.pyi files anyway, but typechecking anything from the generated files with --strict errors because everything is typed as Any, e.g. MyEnum.Value("foo") # Any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions