Skip to content

Commit c55ee08

Browse files
committed
Provide a type alias V on EnumTypeWrapper
This should provide a runtime alias, which can be used in mypy stubs to provide better typing for enum values Fixes #8175
1 parent 6c970b5 commit c55ee08

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

python/google/protobuf/internal/enum_type_wrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ class EnumTypeWrapper(object):
4545

4646
DESCRIPTOR = None
4747

48+
# This is a type alias, which mypy typing stubs can type as
49+
# a genericized parameter constrained to an int, allowing subclasses
50+
# to be typed with more constraint
51+
# Eg.
52+
# def Name(self, number: MyGeneratedEnum.V) -> str
53+
V = int
54+
4855
def __init__(self, enum_type):
4956
"""Inits EnumTypeWrapper with an EnumDescriptor."""
5057
self._enum_type = enum_type

0 commit comments

Comments
 (0)