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.
This commit is contained in:
Jukka Lehtosalo
2023-01-23 09:55:25 +00:00
committed by GitHub
parent ebba92c986
commit d5b88c552c

View File

@@ -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]: ...