Stubs not found when installed in separate venvs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
We're using mypy with Bazel, which installs dependencies into separate directories and manually places the directories on PYTHONPATH. But it seems like this doesn't play well with protobuf, probably because of the initial google/ directory. This only seems to happen with protobuf, can't reproduce with other libraries.
To Reproduce
class FooProto(google.protobuf.message.Message):
x: str
@dataclasses.dataclass
class Foo:
x: str = ""
google.protobuf.message.non_existent()
proto_to_dataclass: Foo = FooProto()
dataclass_to_proto: FooProto = Foo()
See README in https://github.com/brandonchinn178/mypy-repro-protobuf for more details
Expected Behavior
Module has no attribute "non_existent"Incompatible types in assignmentonproto_to_dataclassIncompatible types in assignmentondataclass_to_proto
Actual Behavior
When types-protobuf and protobuf are installed in the same venv, this works (whether mypy is in that environment or a different one). When they're in different venvs, this does not.
Your Environment
- Mypy version used: 1.18.1
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README in the linked mypy-repro-protobuf repository and reproduce the setup with protobuf and types-protobuf installed in separate virtual environments, as described in the issue. Trace how mypy discovers the split google/ package and verify the fix by restoring the three expected diagnostics: the missing attribute and both incompatible assignments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100