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!
This commit is contained in:
Nipunn Koorapati
2020-05-19 07:42:47 +12:00
committed by GitHub
parent f0927787f0
commit 1436181587

View File

@@ -1,10 +1,19 @@
from typing import Any, List, Tuple
from typing import Any, Generic, List, Tuple, TypeVar
class EnumTypeWrapper(object):
def __init__(self, enum_type: Any) -> None: ...
def Name(self, number: int) -> bytes: ...
def Value(self, name: bytes) -> int: ...
def keys(self) -> List[bytes]: ...
def values(self) -> List[int]: ...
@classmethod
def items(cls) -> List[Tuple[bytes, int]]: ...
from google.protobuf.descriptor import EnumDescriptor
_V = TypeVar("_V", bound=int)
# Expose a generic version so that those using mypy-protobuf
# can get autogenerated NewType wrapper around the int values
class _EnumTypeWrapper(Generic[_V]):
DESCRIPTOR: EnumDescriptor
def __init__(self, enum_type: EnumDescriptor) -> None: ...
def Name(self, number: _V) -> str: ...
def Value(self, name: str) -> _V: ...
def keys(self) -> List[str]: ...
def values(self) -> List[_V]: ...
def items(self) -> List[Tuple[str, _V]]: ...
class EnumTypeWrapper(_EnumTypeWrapper[int]): ...