Python enum types are still annotated incorrectly
Maintainers usually reply within 1 day
@jguamie is already working on this.
Since Aug 11, 2026.
Assessment
This issue has not been assessed yet.
Description
What version of protobuf and what language are you using?
Version: commit dd9d2ad02 / protobuf 7.35.1
Language: Python
What supported operating system version are you using (e.g. Linux, Windows) ?
The Python support matrix doesn't indicate any specific OS version requirements.
What supported runtime / compiler version are you using (e.g. python version, gcc version)
Python 3.12.8 w/ mypy 2.1.0
What did you do?
repro.py:
"""protoc-generated enum stubs are inconsistent with EnumTypeWrapper."""
import addressbook_pb2
def phone_number_for(kind: str) -> addressbook_pb2.Person.PhoneNumber:
# PhoneType.Value is stubbed as returning int (EnumTypeWrapper is
# _EnumTypeWrapper[int] in google-stubs)...
phone_type = addressbook_pb2.Person.PhoneType.Value(kind)
# ...but the generated PhoneNumber.__init__ stub expects Person.PhoneType:
#
# error: Argument "type" to "PhoneNumber" has incompatible type "int";
# expected "PhoneType | str | None" [arg-type]
return addressbook_pb2.Person.PhoneNumber(number="555-1234", type=phone_type)
# The generated stub presents PhoneType as a class (an int subclass), but at
# runtime it is an EnumTypeWrapper instance and is not callable:
#
# TypeError: 'EnumTypeWrapper' object is not callable
addressbook_pb2.Person.PhoneType(1)
Steps to reproduce the behavior:
pip install grpcio-tools==1.78.0 types-protobuf mypy
curl -sO https://raw.githubusercontent.com/protocolbuffers/protobuf/main/examples/addressbook.proto
python -m grpc_tools.protoc -I. --python_out=. --pyi_out=. addressbook.proto
python -m mypy repro.py
python repro.py
What did you expect to see
mypyshould not report errors for using the return value fromValue()as the enum type.- Explicitly converting a raw integer type to an enum type should succeed, as if it were an ordinary Python
NewTypedeclaration.
What did you see instead?
$ python -m mypy repro.py
repro.py:18: error: Argument "type" to "PhoneNumber" has incompatible type "int"; expected "PhoneType | str | None" [arg-type]
$ python repro.py
TypeError: 'EnumTypeWrapper' object is not callable
Make sure you include information that can help us debug (protos, full error
message, exception listing, stack trace, logs).
Anything else we should know about your project / environment
This is fundamentally the same issue as #10240, which was auto-closed by a bot without being fixed.
- Dominant language
- C++
- Stars
- 72.2k
- Forks
- 16.4k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 342
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from protocolbuffers/protobuf
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
protocolbuffers/protobuf#31768 ·
Maintainers usually reply within 1 day
-
feature request packaging & distribution python
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
protocolbuffers/protobuf#31654 ·
Maintainers usually reply within 1 day
-
google-protobuf 0.36.2-release fails to compile for ARMv7: @progbits rejected in global_asm!Possibly taken @farisbasha claimed this 1 day ago. Openbug help wanted rust
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
protocolbuffers/protobuf#31619 · 3 comments ·
Maintainers usually reply within 1 day
-
Null pointer passed to memcpy in lupb_decode() when the second argument is nilPossibly taken A pull request linked to this issue is open or already merged. Openbug help wanted lua
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
protocolbuffers/protobuf#31392 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
protocolbuffers/protobuf#31032 ·
Maintainers usually reply within 1 day
All issues in protocolbuffers/protobuf
Similar issues
-
agent:Windows bug in progress pri:medium sev:low testing windows
Difficulty 1/5 Under an hour Newbie friendliness 91/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
godotengine/godot#125651 ·
Maintainers usually reply within 1 day
-
Android: with view recycling on, a recycled View keeps its nextFocusLeftPossibly taken A pull request linked to this issue is open or already merged. OpenNeeds: Triage :mag: Platform: Android
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
react/react-native#60167 ·
Maintainers usually reply within 2 days
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days