From 2f2750f603920771706f26ea81d764c1388c10f3 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 30 Jan 2026 17:17:27 +0100 Subject: [PATCH 1/3] set other/return to Any in object.__eq__ and object.__ne__ --- stdlib/builtins.pyi | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index efc51fe257ae..986c3428b36b 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -121,8 +121,12 @@ 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: ... + # Using 'Any' rather than 'object' for the argument because + # classes may want to restrict the type. + # Using 'Any' rather than 'bool' for the return type because + # classes may want to return a wider type (e.g. numpy array) + def __eq__(self, value: Any, /) -> Any: ... # noqa: Y032 + def __ne__(self, value: Any, /) -> Any: ... # noqa: Y032 def __str__(self) -> str: ... # noqa: Y029 def __repr__(self) -> str: ... # noqa: Y029 def __hash__(self) -> int: ... From 12eb8f285de88e4dc6dd72b136d215be2ba6e527 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 30 Jan 2026 17:30:52 +0100 Subject: [PATCH 2/3] Change return type of object.__eq__ and object.__ne__ to object rather than Any to avoid no-ant-return errors. --- stdlib/builtins.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 986c3428b36b..317d212c77fc 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -123,10 +123,10 @@ class object: def __delattr__(self, name: str, /) -> None: ... # Using 'Any' rather than 'object' for the argument because # classes may want to restrict the type. - # Using 'Any' rather than 'bool' for the return type because + # Using 'object' rather than 'bool' for the return type because # classes may want to return a wider type (e.g. numpy array) - def __eq__(self, value: Any, /) -> Any: ... # noqa: Y032 - def __ne__(self, value: Any, /) -> Any: ... # noqa: Y032 + def __eq__(self, value: Any, /) -> object: ... # noqa: Y032 + def __ne__(self, value: Any, /) -> object: ... # noqa: Y032 def __str__(self) -> str: ... # noqa: Y029 def __repr__(self) -> str: ... # noqa: Y029 def __hash__(self) -> int: ... From ec07cf9e5d54a8a4a9fc55bbca52ea71a42f7088 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Fri, 30 Jan 2026 17:40:43 +0100 Subject: [PATCH 3/3] try with Any | bool --- stdlib/builtins.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 317d212c77fc..10409039f17b 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -123,10 +123,10 @@ class object: def __delattr__(self, name: str, /) -> None: ... # Using 'Any' rather than 'object' for the argument because # classes may want to restrict the type. - # Using 'object' rather than 'bool' for the return type because + # Using 'Any | bool' rather than 'bool' for the return type because # classes may want to return a wider type (e.g. numpy array) - def __eq__(self, value: Any, /) -> object: ... # noqa: Y032 - def __ne__(self, value: Any, /) -> object: ... # noqa: Y032 + def __eq__(self, value: Any, /) -> Any | bool: ... # noqa: Y032 + def __ne__(self, value: Any, /) -> Any | bool: ... # noqa: Y032 def __str__(self) -> str: ... # noqa: Y029 def __repr__(self) -> str: ... # noqa: Y029 def __hash__(self) -> int: ...