Skip to content

Commit

Permalink
Provide a type alias V on EnumTypeWrapper
Browse files Browse the repository at this point in the history
This should provide a runtime alias, which can be
used in mypy stubs to provide better typing for enum values

Fixes #8175
  • Loading branch information
nipunn1313 committed Jun 30, 2021
1 parent e60ec85 commit 4e45b46
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python/google/protobuf/internal/enum_type_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class EnumTypeWrapper(object):

DESCRIPTOR = None

# This is a type alias, which mypy typing stubs can type as
# a genericized parameter constrained to an int, allowing subclasses
# to be typed with more constraint
# Eg.
# def Name(self, number: MyGeneratedEnum.V) -> str
V = int

def __init__(self, enum_type):
"""Inits EnumTypeWrapper with an EnumDescriptor."""
self._enum_type = enum_type
Expand Down

0 comments on commit 4e45b46

Please sign in to comment.