From d5b88c552cd7530b598b6369fef66bda745de93d Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 23 Jan 2023 09:55:25 +0000 Subject: [PATCH] Add __eq__ to types.MappingProxyType (#9580) The type has a custom __eq__: https://github.com/python/cpython/blob/v3.11.1/Objects/descrobject.c#L1906 This helps fix this mypy false positive when using `--strict-equality`: ``` from types import MappingProxyType p = MappingProxyType({'x': 1}) d = {'x': 1} print(p == d) # error: Non-overlapping equality check ``` The fragment prints `True` so the comparison is valid. --- stdlib/types.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/types.pyi b/stdlib/types.pyi index d4069c672..793e9220f 100644 --- a/stdlib/types.pyi +++ b/stdlib/types.pyi @@ -310,6 +310,7 @@ class MappingProxyType(Mapping[_KT, _VT_co], Generic[_KT, _VT_co]): def __getitem__(self, __key: _KT) -> _VT_co: ... def __iter__(self) -> Iterator[_KT]: ... def __len__(self) -> int: ... + def __eq__(self, other: object) -> bool: ... def copy(self) -> dict[_KT, _VT_co]: ... def keys(self) -> KeysView[_KT]: ... def values(self) -> ValuesView[_VT_co]: ...