experiment: remove `__eq__` from `object` by randolf-scholz · Pull Request #16348 · python/typeshed · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/@tests/test_cases/check_pathlib.py
73 changes: 50 additions & 23 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ class object:
# Overriding them in subclasses has different semantics, even if the override has an identical signature.
def __setattr__(self, name: str, value: Any, /) -> None: ...
def __delattr__(self, name: str, /) -> None: ...
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
# intentionally removed. objects should be compared via `is`.
# def __eq__(self, value: object, /) -> bool: ...
# def __ne__(self, value: object, /) -> bool: ...
def __str__(self) -> str: ... # noqa: Y029
def __repr__(self) -> str: ... # noqa: Y029
def __hash__(self) -> int: ...
Expand Down Expand Up @@ -350,8 +351,8 @@ class int:
def __round__(self, ndigits: SupportsIndex = ..., /) -> int: ...

def __getnewargs__(self) -> tuple[int]: ...
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __eq__(self, value: int, /) -> bool: ...
def __ne__(self, value: int, /) -> bool: ...
def __lt__(self, value: int, /) -> bool: ...
def __le__(self, value: int, /) -> bool: ...
def __gt__(self, value: int, /) -> bool: ...
Expand Down Expand Up @@ -418,8 +419,8 @@ class float:
@overload
def __round__(self, ndigits: SupportsIndex, /) -> float: ...

def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __eq__(self, value: float | int, /) -> bool: ...
def __ne__(self, value: float | int, /) -> bool: ...
def __lt__(self, value: float, /) -> bool: ...
def __le__(self, value: float, /) -> bool: ...
def __gt__(self, value: float, /) -> bool: ...
Expand Down Expand Up @@ -463,8 +464,8 @@ class complex:
def __rmul__(self, value: complex, /) -> complex: ...
def __rpow__(self, value: complex, mod: None = None, /) -> complex: ...
def __rtruediv__(self, value: complex, /) -> complex: ...
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __eq__(self, value: complex | float | int, /) -> bool: ...
def __ne__(self, value: complex | float | int, /) -> bool: ...
def __neg__(self) -> complex: ...
def __pos__(self) -> complex: ...
def __abs__(self) -> float: ...
Expand Down Expand Up @@ -687,7 +688,8 @@ class str(Sequence[str]):

# Incompatible with Sequence.__contains__
def __contains__(self, key: str, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: str, /) -> bool: ...
def __ne__(self, value: str, /) -> bool: ...
def __ge__(self, value: str, /) -> bool: ...

@overload
Expand Down Expand Up @@ -717,8 +719,6 @@ class str(Sequence[str]):
@overload
def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc]

def __ne__(self, value: object, /) -> bool: ...

@overload
def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ...
@overload
Expand Down Expand Up @@ -828,8 +828,8 @@ class bytes(Sequence[int]):
def __mod__(self, value: Any, /) -> bytes: ...
# Incompatible with Sequence.__contains__
def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __eq__(self, value: bytes, /) -> bool: ...
def __ne__(self, value: bytes, /) -> bool: ...
def __lt__(self, value: bytes, /) -> bool: ...
def __le__(self, value: bytes, /) -> bool: ...
def __gt__(self, value: bytes, /) -> bool: ...
Expand Down Expand Up @@ -959,8 +959,8 @@ class bytearray(MutableSequence[int]):
def __mod__(self, value: Any, /) -> bytes: ...
# Incompatible with Sequence.__contains__
def __contains__(self, key: SupportsIndex | ReadableBuffer, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __ne__(self, value: object, /) -> bool: ...
def __eq__(self, value: ReadableBuffer, /) -> bool: ...
def __ne__(self, value: ReadableBuffer, /) -> bool: ...
def __lt__(self, value: ReadableBuffer, /) -> bool: ...
def __le__(self, value: ReadableBuffer, /) -> bool: ...
def __gt__(self, value: ReadableBuffer, /) -> bool: ...
Expand Down Expand Up @@ -1028,7 +1028,12 @@ class memoryview(Sequence[_I]):
def __contains__(self, x: object, /) -> bool: ...
def __iter__(self) -> Iterator[_I]: ...
def __len__(self) -> int: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: ReadableBuffer, /) -> bool: ...
def __ne__(self, value: ReadableBuffer, /) -> bool: ...
def __lt__(self, value: ReadableBuffer, /) -> bool: ...
def __le__(self, value: ReadableBuffer, /) -> bool: ...
def __gt__(self, value: ReadableBuffer, /) -> bool: ...
def __ge__(self, value: ReadableBuffer, /) -> bool: ...
def __hash__(self) -> int: ...

@overload
Expand Down Expand Up @@ -1130,7 +1135,13 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]):
@overload
def __new__(cls, start: _T1, stop: _T2, step: _T3, /) -> slice[_T1, _T2, _T3]: ...

def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: slice, /) -> bool: ...
def __ne__(self, value: slice, /) -> bool: ...
# surprisingly, these are implemented and delagate to tuple comparison
def __ge__(self, value: slice, /) -> bool: ...
def __gt__(self, value: slice, /) -> bool: ...
def __le__(self, value: slice, /) -> bool: ...
def __lt__(self, value: slice, /) -> bool: ...
if sys.version_info >= (3, 12):
def __hash__(self) -> int: ...

Expand All @@ -1157,7 +1168,8 @@ class tuple(Sequence[_T_co]):
def __le__(self, value: tuple[_T_co, ...], /) -> bool: ...
def __gt__(self, value: tuple[_T_co, ...], /) -> bool: ...
def __ge__(self, value: tuple[_T_co, ...], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: tuple, /) -> bool: ...
def __ne__(self, value: tuple, /) -> bool: ...
def __hash__(self) -> int: ...

@overload
Expand Down Expand Up @@ -1282,7 +1294,8 @@ class list(MutableSequence[_T]):
def __ge__(self, value: list[_T], /) -> bool: ...
def __lt__(self, value: list[_T], /) -> bool: ...
def __le__(self, value: list[_T], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: list, /) -> bool: ...
def __ne__(self, value: list, /) -> bool: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

@disjoint_base
Expand Down Expand Up @@ -1355,7 +1368,13 @@ class dict(MutableMapping[_KT, _VT]):
def __setitem__(self, key: _KT, value: _VT, /) -> None: ...
def __delitem__(self, key: _KT, /) -> None: ...
def __iter__(self) -> Iterator[_KT]: ...
def __eq__(self, value: object, /) -> bool: ...
if sys.version_info >= (3, 15):
def __eq__(self, value: dict | frozendict, /) -> bool: ... # type: ignore[override]
def __ne__(self, value: dict | frozendict, /) -> bool: ... # type: ignore[override]
else:
def __eq__(self, value: dict, /) -> bool: ... # type: ignore[override]
def __ne__(self, value: dict, /) -> bool: ... # type: ignore[override]

def __reversed__(self) -> Iterator[_KT]: ...
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
Expand Down Expand Up @@ -1397,6 +1416,9 @@ if sys.version_info >= (3, 15):
cls: type[frozendict[str, _VT]], iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT
) -> frozendict[str, _VT]: ...

# overrides Mapping.__eq__, and only supports comparison with dict/frozendict
def __eq__(self, value: dict | frozendict, /) -> bool: ... # type: ignore[override]
def __ne__(self, value: dict | frozendict, /) -> bool: ... # type: ignore[override]
def copy(self) -> frozendict[_KT, _VT]: ...

@overload
Expand Down Expand Up @@ -1466,7 +1488,9 @@ class set(MutableSet[_T]):
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
# overrides MutableSet.__eq__ and only supports comparison with set/frozenset
def __eq__(self, value: set | frozenset, /) -> bool: ... # type: ignore[override]
def __ne__(self, value: set | frozenset, /) -> bool: ... # type: ignore[override]
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

Expand Down Expand Up @@ -1496,7 +1520,9 @@ class frozenset(AbstractSet[_T_co]):
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
# overrides AbstractSet.__eq__ and only supports comparison with set/frozenset
def __eq__(self, value: set | frozenset, /) -> bool: ... # type: ignore[override]
def __ne__(self, value: set | frozenset, /) -> bool: ... # type: ignore[override]
def __hash__(self) -> int: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

Expand Down Expand Up @@ -1524,7 +1550,8 @@ class range(Sequence[int]):
def count(self, value: int, /) -> int: ...
def index(self, value: int, /) -> int: ... # type: ignore[override]
def __len__(self) -> int: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: range, /) -> bool: ...
def __ne__(self, value: range, /) -> bool: ...
def __hash__(self) -> int: ...
def __contains__(self, key: object, /) -> bool: ...
def __iter__(self) -> Iterator[int]: ...
Expand Down
12 changes: 5 additions & 7 deletions stdlib/collections/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class UserList(MutableSequence[_T]):
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __ge__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def __eq__(self, other: list | UserList) -> bool: ...
def __contains__(self, item: object) -> bool: ...
def __len__(self) -> int: ...

Expand Down Expand Up @@ -182,7 +182,7 @@ class UserString(Sequence[UserString]):
def __le__(self, string: str | UserString) -> bool: ...
def __gt__(self, string: str | UserString) -> bool: ...
def __ge__(self, string: str | UserString) -> bool: ...
def __eq__(self, string: object) -> bool: ...
def __eq__(self, string: str | UserString) -> bool: ...
def __hash__(self) -> int: ...
def __contains__(self, char: object) -> bool: ...
def __len__(self) -> int: ...
Expand Down Expand Up @@ -283,7 +283,7 @@ class deque(MutableSequence[_T]):
def __le__(self, value: deque[_T], /) -> bool: ...
def __gt__(self, value: deque[_T], /) -> bool: ...
def __ge__(self, value: deque[_T], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: deque, /) -> bool: ...
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

class Counter(dict[_T, int], Generic[_T]):
Expand Down Expand Up @@ -325,8 +325,8 @@ class Counter(dict[_T, int], Generic[_T]):
def total(self) -> int: ...
def __missing__(self, key: _T) -> int: ...
def __delitem__(self, elem: object) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
def __eq__(self, other: Counter) -> bool: ... # type: ignore[override]
def __ne__(self, other: Counter) -> bool: ... # type: ignore[override]
def __le__(self, other: Counter[Any]) -> bool: ...
def __lt__(self, other: Counter[Any]) -> bool: ...
def __ge__(self, other: Counter[Any]) -> bool: ...
Expand Down Expand Up @@ -412,8 +412,6 @@ class OrderedDict(dict[_KT, _VT]):
@overload
def pop(self, key: _KT, default: _T) -> _VT | _T: ...

def __eq__(self, value: object, /) -> bool: ...

if sys.version_info >= (3, 15):
@overload
def __or__(self, value: dict[_KT, _VT] | frozendict[_KT, _VT], /) -> Self: ...
Expand Down
10 changes: 5 additions & 5 deletions stdlib/datetime.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class timezone(tzinfo):
def utcoffset(self, dt: datetime | None, /) -> timedelta: ...
def dst(self, dt: datetime | None, /) -> None: ...
def __hash__(self) -> int: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: timezone, /) -> bool: ...

if sys.version_info >= (3, 11):
UTC: timezone
Expand Down Expand Up @@ -109,7 +109,7 @@ class date:
def __lt__(self, value: date, /) -> bool: ...
def __ge__(self, value: date, /) -> bool: ...
def __gt__(self, value: date, /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: date, /) -> bool: ...
def __add__(self, value: timedelta, /) -> Self: ...
def __radd__(self, value: timedelta, /) -> Self: ...

Expand Down Expand Up @@ -156,7 +156,7 @@ class time:
def __lt__(self, value: time, /) -> bool: ...
def __ge__(self, value: time, /) -> bool: ...
def __gt__(self, value: time, /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: time, /) -> bool: ...
def __hash__(self) -> int: ...
def isoformat(self, timespec: str = "auto") -> str: ...

Expand Down Expand Up @@ -262,7 +262,7 @@ class timedelta:
def __lt__(self, value: timedelta, /) -> bool: ...
def __ge__(self, value: timedelta, /) -> bool: ...
def __gt__(self, value: timedelta, /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: timedelta, /) -> bool: ...
def __bool__(self) -> bool: ...
def __hash__(self) -> int: ...

Expand Down Expand Up @@ -370,7 +370,7 @@ class datetime(date):
def __lt__(self, value: datetime, /) -> bool: ... # type: ignore[override]
def __ge__(self, value: datetime, /) -> bool: ... # type: ignore[override]
def __gt__(self, value: datetime, /) -> bool: ... # type: ignore[override]
def __eq__(self, value: object, /) -> bool: ...
def __eq__(self, value: datetime, /) -> bool: ... # type: ignore[override]
def __hash__(self) -> int: ...

@overload # type: ignore[override]
Expand Down
1 change: 1 addition & 0 deletions stdlib/pathlib/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class PurePath(PathLike[str]):
if sys.version_info >= (3, 15):
def __vfspath__(self) -> str: ...

def __eq__(self, other: PurePath) -> bool: ...
def __lt__(self, other: PurePath) -> bool: ...
def __le__(self, other: PurePath) -> bool: ...
def __gt__(self, other: PurePath) -> bool: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ class AbstractSet(Collection[_T_co]):
def __or__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ...
def __sub__(self, other: AbstractSet[Any], /) -> AbstractSet[_T_co]: ...
def __xor__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ...
def __eq__(self, other: object, /) -> bool: ...
def __eq__(self, other: AbstractSet, /) -> bool: ...
def isdisjoint(self, other: Iterable[Any], /) -> bool: ...

class MutableSet(AbstractSet[_T]):
Expand Down Expand Up @@ -822,7 +822,7 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
def keys(self) -> KeysView[_KT]: ...
def values(self) -> ValuesView[_VT_co]: ...
def __contains__(self, key: object, /) -> bool: ...
def __eq__(self, other: object, /) -> bool: ...
def __eq__(self, other: Mapping, /) -> bool: ...

class MutableMapping(Mapping[_KT, _VT]):
@abstractmethod
Expand Down Expand Up @@ -1187,7 +1187,7 @@ else:
self, globalns: dict[str, Any] | None, localns: Mapping[str, Any] | None, recursive_guard: frozenset[str]
) -> Any | None: ... # AnnotationForm

def __eq__(self, other: object) -> bool: ...
def __eq__(self, other: ForwardRef, /) -> bool: ...
def __hash__(self) -> int: ...
if sys.version_info >= (3, 11):
def __or__(self, other: Any) -> _SpecialForm: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/networkx/networkx/classes/reportviews.pyi
Loading