Skip to content

Commit

Permalink
Extract integer type (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
henribru authored Nov 14, 2023
1 parent e9a7f69 commit e8c5284
Showing 1 changed file with 27 additions and 168 deletions.
195 changes: 27 additions & 168 deletions proto-stubs/fields.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ from .primitives import ProtoType

T = TypeVar("T")

_IntegerProtoType = Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
]

class Field(Generic[T]):
repeated: bool
mcls_data: Any
Expand All @@ -28,18 +41,7 @@ class Field(Generic[T]):
@overload
def __init__(
self: Field[int],
proto_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
proto_type: _IntegerProtoType,
*,
number: int,
oneof: str = ...,
Expand Down Expand Up @@ -155,18 +157,7 @@ class RepeatedField(Field[T]):
@overload
def __init__(
self: RepeatedField[int],
proto_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
proto_type: _IntegerProtoType,
*,
number: int,
oneof: str = ...,
Expand Down Expand Up @@ -267,124 +258,47 @@ class MapField(Field[V], Generic[K, V]):
@overload
def __init__(
self: MapField[int, float],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.DOUBLE, ProtoType.FLOAT],
*,
number: int,
) -> None: ...
@overload
def __init__(
self: MapField[int, int],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
value_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: _IntegerProtoType,
*,
number: int,
) -> None: ...
@overload
def __init__(
self: MapField[int, bool],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.BOOL],
*,
number: int,
) -> None: ...
@overload
def __init__(
self: MapField[int, str],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.STRING],
*,
number: int,
) -> None: ...
@overload
def __init__(
self: MapField[int, bytes],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.BYTES],
*,
number: int,
) -> None: ...
@overload
def __init__(
self: MapField[int, V],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.MESSAGE],
*,
number: int,
Expand All @@ -393,18 +307,7 @@ class MapField(Field[V], Generic[K, V]):
@overload
def __init__(
self: MapField[int, V],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.ENUM],
*,
number: int,
Expand All @@ -413,37 +316,15 @@ class MapField(Field[V], Generic[K, V]):
@overload
def __init__(
self: MapField[int, V],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: type[V],
*,
number: int,
) -> None: ...
@overload
def __init__(
self: MapField[int, Any],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.MESSAGE],
*,
number: int,
Expand All @@ -452,18 +333,7 @@ class MapField(Field[V], Generic[K, V]):
@overload
def __init__(
self: MapField[int, Any],
key_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
key_type: _IntegerProtoType,
value_type: Literal[ProtoType.ENUM],
*,
number: int,
Expand All @@ -481,18 +351,7 @@ class MapField(Field[V], Generic[K, V]):
def __init__(
self: MapField[str, int],
key_type: Literal[ProtoType.STRING],
value_type: Literal[
ProtoType.INT64,
ProtoType.UINT64,
ProtoType.INT32,
ProtoType.FIXED64,
ProtoType.FIXED32,
ProtoType.UINT32,
ProtoType.SFIXED32,
ProtoType.SFIXED64,
ProtoType.SINT32,
ProtoType.SINT64,
],
value_type: _IntegerProtoType,
*,
number: int,
) -> None: ...
Expand Down

0 comments on commit e8c5284

Please sign in to comment.