Skip to content

Commit

Permalink
Fix or silence pyre type errors
Browse files Browse the repository at this point in the history
Summary: Fix or silence the type errors after pyre version upgrade

Reviewed By: createdbysk

Differential Revision: D65384752

fbshipit-source-id: 882f76e7b0bb37671fe5c72d971f44773388779e
  • Loading branch information
yoney authored and facebook-github-bot committed Nov 3, 2024
1 parent 60146f0 commit 6c55aa9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions thrift/lib/python/any/serializer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def serialize_primitive(
) -> IOBuf: ...
def deserialize_primitive(
cls: typing.Type[TPrimitive],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = ...,
thrift_type: typing.Optional[Type] = ...,
Expand All @@ -51,6 +52,7 @@ def serialize_list(
) -> IOBuf: ...
def deserialize_list(
elem_cls: typing.Type[TSerializable],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = ...,
) -> typing.Sequence[TSerializable]: ...
Expand All @@ -60,6 +62,7 @@ def serialize_set(
) -> IOBuf: ...
def deserialize_set(
elem_cls: typing.Type[TSerializable],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = ...,
) -> typing.AbstractSet[TSerializable]: ...
Expand All @@ -70,6 +73,7 @@ def serialize_map(
def deserialize_map(
key_cls: typing.Type[TKey],
value_cls: typing.Type[TValue],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = ...,
) -> typing.Mapping[TKey, TValue]: ...
Expand Down
2 changes: 2 additions & 0 deletions thrift/lib/python/common.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Priority(Enum):
class Headers(Mapping[str, str]):
def __repr__(self) -> str: ...
def __len__(self) -> int: ...
# pyre-fixme[14]: `__contains__` overrides method defined in `Mapping`
# inconsistently.
def __contains__(self, o: object) -> bool: ...
def __getitem__(self, key: str) -> str: ...
def __iter__(self) -> Iterator[str]: ...
Expand Down
6 changes: 6 additions & 0 deletions thrift/lib/python/mutable_containers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MutableList(MutableSequence[T]):
@overload
def __getitem__(self, index: int) -> T: ...
@overload
# pyre-fixme[24]: Generic type `slice` expects 3 type parameters.
def __getitem__(self, index: slice) -> MutableList[T]: ...
@overload
def __setitem__(self, index: int, value: T) -> None: ...
Expand All @@ -71,6 +72,7 @@ class MutableList(MutableSequence[T]):
@overload
def __delitem__(self, index: int) -> None: ...
@overload
# pyre-fixme[24]: Generic type `slice` expects 3 type parameters.
def __delitem__(self, index: slice) -> None: ...
@overload
def insert(self, index: int, value: T) -> None: ...
Expand Down Expand Up @@ -200,6 +202,7 @@ class MutableMap(Generic[K, V]):
val_typeinfo: object,
map_data: Mapping[object, object],
) -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, key: K) -> V: ...
def __iter__(self) -> ValueIterator[K]: ...
def get(self, key: K, default: Optional[V] = None) -> V: ...
Expand Down Expand Up @@ -243,10 +246,12 @@ class MutableMap(Generic[K, V]):
def setdefault(self, key: object, default: typing.Optional[object] = None) -> V: ...

class MapKeysView(Generic[K]):
def __len__(self) -> int: ...
def __contains__(self, key: object) -> bool: ...
def __iter__(self) -> ValueIterator[K]: ...

class MapItemsView(Generic[K, V]):
def __len__(self) -> int: ...
def __contains__(self, key: K) -> bool: ...
def __iter__(self) -> MapItemIterator[tuple[K, V]]: ...

Expand All @@ -255,4 +260,5 @@ class MapItemIterator(Iterator[T]):
def __iter__(self) -> MapItemIterator[T]: ...

class MapValuesView(Generic[V]):
def __len__(self) -> int: ...
def __iter__(self) -> ValueIterator[V]: ...
2 changes: 2 additions & 0 deletions thrift/lib/python/mutable_serializer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ def serialize_iobuf(strct: sT, protocol: Protocol = Protocol.COMPACT) -> IOBuf:
def serialize(struct: sT, protocol: Protocol = Protocol.COMPACT) -> bytes: ...
def deserialize_with_length(
klass: typing.Type[sT],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = Protocol.COMPACT,
) -> typing.Tuple[sT, int]: ...
def deserialize(
klass: typing.Type[sT],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = Protocol.COMPACT,
) -> sT: ...
2 changes: 2 additions & 0 deletions thrift/lib/python/serializer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def serialize_iobuf(strct: sT, protocol: Protocol = Protocol.COMPACT) -> IOBuf:
def serialize(struct: sT, protocol: Protocol = Protocol.COMPACT) -> bytes: ...
def deserialize_with_length(
klass: typing.Type[sT],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = Protocol.COMPACT,
*,
fully_populate_cache: bool = False,
) -> typing.Tuple[sT, int]: ...
def deserialize(
klass: typing.Type[sT],
# pyre-fixme[24]: Generic type `memoryview` expects 1 type parameter.
buf: typing.Union[bytes, bytearray, IOBuf, memoryview],
protocol: Protocol = Protocol.COMPACT,
*,
Expand Down
9 changes: 9 additions & 0 deletions thrift/lib/python/test/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,18 @@ def test_getitem(self) -> None:
self.assertEqual(x["test"], "value")
self.assertEqual(x[MyStringEnum.test], "value")
with self.assertRaises(KeyError):
# pyre-ignore[6]: Intentional for test
x[5]
with self.assertRaises(KeyError):
# pyre-ignore[6]: Intentional for test
x[x]

def test_get(self) -> None:
x = self.StrStrMap({"test": "value"})
self.assertEqual(x.get("test"), "value")
# pyre-ignore[6]: Intentional for test
self.assertIs(x.get(5), None)
# pyre-ignore[6]: Intentional for test
self.assertIs(x.get(x), None)

def test_contains(self) -> None:
Expand Down Expand Up @@ -313,11 +317,16 @@ def test_contains_enum(self) -> None:
self.assertIn(1, cmap.colorMap)
self.assertNotIn(2, cmap.colorMap)
# gross
# pyre-ignore[6]: Intentional for test
self.assertEqual(cmap.colorMap[0], self.Color.red)
# pyre-ignore[6]: Intentional for test
self.assertEqual(cmap.colorMap[1], self.Color.blue)

# pyre-ignore[6]: Intentional for test
self.assertEqual(cmap.colorMap.get(0), self.Color.red)
# pyre-ignore[6]: Intentional for test
self.assertEqual(cmap.colorMap.get(1), self.Color.blue)
# pyre-ignore[6]: Intentional for test
self.assertEqual(cmap.colorMap.get(2), None)


Expand Down

0 comments on commit 6c55aa9

Please sign in to comment.