Python enum types are still annotated incorrectly
I maintainer di solito rispondono entro 1 giorno
@jguamie ci sta già lavorando.
Dal 11/8/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- C++
- Stelle
- 72.2k
- Fork
- 16.4k
- Merge medio
- 1g 8h
- PR unite (30g)
- 342
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di protocolbuffers/protobuf
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
protocolbuffers/protobuf#31768 ·
I maintainer di solito rispondono entro 1 giorno
-
feature request packaging & distribution python
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31654 ·
I maintainer di solito rispondono entro 1 giorno
-
google-protobuf 0.36.2-release fails to compile for ARMv7: @progbits rejected in global_asm!Forse già presa @farisbasha l’ha presa 2 giorni fa. Apertabug help wanted rust
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31619 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Null pointer passed to memcpy in lupb_decode() when the second argument is nilForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug help wanted lua
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
protocolbuffers/protobuf#31392 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
upb: JSON encoder does not range-check Duration and Timestamp nanos (signed overflow on -2^31)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
protocolbuffers/protobuf#31032 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di protocolbuffers/protobuf
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
I maintainer di solito rispondono entro 7 giorni
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
microsoft/DirectXShaderCompiler#9155 ·
I maintainer di solito rispondono entro 2 giorni
-
Errors in 1.20 proseApertaCampaign DiD Campaign EI Campaign HttT Campaign TDG Campaign TSG Campaign WoF Enhancement Help Prose Stable 1.20
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
wesnoth/wesnoth#11749 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno