Skip to content

Commit

Permalink
MutableMap should implement container.abc.MutableMapping
Browse files Browse the repository at this point in the history
Summary:
type-checks for generated code fail with the errors below.

```
[2024-11-16T21:45:14.168-08:00] Found type errors!
[2024-11-16T21:45:14.168-08:00] buck-out/v2/gen/fbcode/3cc3cae8ebb1ba74/thrift/test/thrift-python/__struct_test_thrift_with_abstract-python-struct_test.thrift__/out/gen-python/thrift/test/thrift_python/struct_test/thrift_mutable_types.pyi:532:4 Inconsistent override [15]: `thrift.test.thrift_python.struct_test.thrift_mutable_types.TestStructContainerAssignment.__iter__` overrides method defined in `_fbthrift_python_abstract_types.TestStructContainerAssignment` inconsistently. Returned type `_typing.Iterator[_typing.Tuple[str, _typing.Union[_fbthrift_python_mutable_containers.MutableList[_fbthrift_python_mutable_containers.MutableList[int]], _fbthrift_python_mutable_containers.MutableList[TestStructAsListElement], _fbthrift_python_mutable_containers.MutableList[int], _fbthrift_python_mutable_containers.MutableMap[int, _fbthrift_python_mutable_containers.MutableList[int]], _fbthrift_python_mutable_containers.MutableSet[str]]]]` is not a subtype of the overridden return `_typing.Iterator[_typing.Tuple[str, _typing.Union[_typing.AbstractSet[str], _typing.Mapping[int, _typing.Sequence[int]], _typing.Sequence[_typing.Sequence[int]], _typing.Sequence[_fbthrift_python_abstract_types.TestStructAsListElement], _typing.Sequence[int]]]]`.
[2024-11-16T21:45:14.168-08:00] buck-out/v2/gen/fbcode/3cc3cae8ebb1ba74/thrift/test/thrift-python/__struct_test_thrift_with_abstract-python-struct_test.thrift__/out/gen-python/thrift/test/thrift_python/struct_test/thrift_mutable_types.pyi:1116:4 Inconsistent override [15]: `thrift.test.thrift_python.struct_test.thrift_mutable_types.TestStructCopy.__iter__` overrides method defined in `_fbthrift_python_abstract_types.TestStructCopy` inconsistently. Returned type `_typing.Iterator[_typing.Tuple[str, _typing.Union[_fbthrift_python_mutable_containers.MutableList[int], _fbthrift_python_mutable_containers.MutableMap[str, int], _fbthrift_python_mutable_containers.MutableSet[str], TestStructCopy, _fbthrift_iobuf.IOBuf, int, str]]]` is not a subtype of the overridden return `_typing.Iterator[_typing.Tuple[str, _typing.Union[_typing.AbstractSet[str], _typing.Mapping[str, int], _typing.Sequence[int], _fbthrift_iobuf.IOBuf, _fbthrift_python_abstract_types.TestStructCopy, int, str]]]`.
[2024-11-16T21:45:14.168-08:00] buck-out/v2/gen/fbcode/3cc3cae8ebb1ba74/thrift/test/thrift-python/__struct_test_thrift_with_abstract-python-struct_test.thrift__/out/gen-python/thrift/test/thrift_python/struct_test/thrift_mutable_types.pyi:1202:4 Inconsistent override [15]: `thrift.test.thrift_python.struct_test.thrift_mutable_types.TestExceptionCopy.__iter__` overrides method defined in `_fbthrift_python_abstract_types.TestExceptionCopy` inconsistently. Returned type `_typing.Iterator[_typing.Tuple[str, _typing.Union[_fbthrift_python_mutable_containers.MutableList[int], _fbthrift_python_mutable_containers.MutableMap[str, int], _fbthrift_python_mutable_containers.MutableSet[str], TestExceptionCopy, int, str]]]` is not a subtype of the overridden return `_typing.Iterator[_typing.Tuple[str, _typing.Union[_typing.AbstractSet[str], _typing.Mapping[str, int], _typing.Sequence[int], _fbthrift_python_abstract_types.TestExceptionCopy, int, str]]]`.
```

Reviewed By: yoney

Differential Revision: D66067300

fbshipit-source-id: 876b1d2311cd88499eb0106475493318478c3164
  • Loading branch information
Satish Kumar authored and facebook-github-bot committed Nov 18, 2024
1 parent 823a95e commit b05d062
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions third-party/thrift/src/thrift/lib/python/mutable_containers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
# pyre-strict

import typing
from collections.abc import Iterator, MutableSequence, MutableSet as MutableSetAbc
from collections.abc import (
Iterator,
MutableMapping as MutableMappingAbc,
MutableSequence,
MutableSet as MutableSetAbc,
)
from typing import (
Any,
Generic,
Expand Down Expand Up @@ -195,7 +200,7 @@ V = TypeVar("V")
_K = TypeVar("_K")
_V = TypeVar("_V")

class MutableMap(Generic[K, V]):
class MutableMap(MutableMappingAbc[K, V]):
def __init__(
self,
key_typeinfo: object,
Expand All @@ -205,6 +210,7 @@ class MutableMap(Generic[K, V]):
def __len__(self) -> int: ...
def __getitem__(self, key: K) -> V: ...
def __iter__(self) -> ValueIterator[K]: ...
# pyre-ignore[14]: Inconsistent override
def get(self, key: K, default: Optional[V] = None) -> V: ...
@overload
def __setitem__(self, key: K, value: V) -> None: ...
Expand All @@ -228,6 +234,7 @@ class MutableMap(Generic[K, V]):
) -> None: ...
def __delitem__(self, key: K) -> None: ...
def __contains__(self, key: T) -> bool: ...
# pyre-ignore[14]: Inconsistent override
def update(
self,
other: Union[
Expand All @@ -237,12 +244,17 @@ class MutableMap(Generic[K, V]):
/,
**keywords: object,
) -> None: ...
# pyre-ignore[14]: Inconsistent override
def pop(self, key: T, default: Optional[object] = MapKwargsSentinelType()) -> V: ...
def popitem(self) -> Tuple[K, V]: ...
def clear(self) -> None: ...
# pyre-ignore[15]: Inconsistent override
def keys(self) -> MapKeysView[K]: ...
# pyre-ignore[15]: Inconsistent override
def items(self) -> MapItemsView[K, V]: ...
# pyre-ignore[15]: Inconsistent override
def values(self) -> MapValuesView[V]: ...
# pyre-ignore[14]: Inconsistent override
def setdefault(self, key: object, default: typing.Optional[object] = None) -> V: ...

class MapKeysView(Generic[K]):
Expand Down

0 comments on commit b05d062

Please sign in to comment.