Skip to content

Commit 1436181

Browse files
authored
Make EnumTypeWrapper generic in google.protobuf.internal (#3995)
This is necessary so that mypy-protobuf can autogenerate NewType wrappers around the int values of the enum!
1 parent f092778 commit 1436181

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
from typing import Any, List, Tuple
2-
3-
class EnumTypeWrapper(object):
4-
def __init__(self, enum_type: Any) -> None: ...
5-
def Name(self, number: int) -> bytes: ...
6-
def Value(self, name: bytes) -> int: ...
7-
def keys(self) -> List[bytes]: ...
8-
def values(self) -> List[int]: ...
9-
@classmethod
10-
def items(cls) -> List[Tuple[bytes, int]]: ...
1+
from typing import Any, Generic, List, Tuple, TypeVar
2+
3+
from google.protobuf.descriptor import EnumDescriptor
4+
5+
_V = TypeVar("_V", bound=int)
6+
7+
# Expose a generic version so that those using mypy-protobuf
8+
# can get autogenerated NewType wrapper around the int values
9+
class _EnumTypeWrapper(Generic[_V]):
10+
DESCRIPTOR: EnumDescriptor
11+
12+
def __init__(self, enum_type: EnumDescriptor) -> None: ...
13+
def Name(self, number: _V) -> str: ...
14+
def Value(self, name: str) -> _V: ...
15+
def keys(self) -> List[str]: ...
16+
def values(self) -> List[_V]: ...
17+
def items(self) -> List[Tuple[str, _V]]: ...
18+
19+
class EnumTypeWrapper(_EnumTypeWrapper[int]): ...

0 commit comments

Comments
 (0)