From 04d5ff6ff0845b10c5c578a48afbe59639cfca4e Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:53:44 +0200 Subject: [PATCH 1/6] Clarify the special no-TypeError behavior for equality --- Doc/reference/datamodel.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index cc81f73f824352..4f81175b157aa9 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1613,6 +1613,12 @@ Basic customization the left operand's method has priority. Virtual subclassing is not considered. + When no method returns any value other than NotImplemented, comparisons raise + a :exc:`TypeError`. However, the `==` and `!=` operators will not raise an + exception in that case, and will instead fall back to `is` and `is not`, + respectively. That way, even though `object().__eq__(object())` returns + NotImplemented, `object() == object()` returns False. + .. method:: object.__hash__(self) .. index:: From 5746dcc993c93a5b93a39626cea6e300c8befe74 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Wed, 11 Oct 2023 18:05:29 +0200 Subject: [PATCH 2/6] of course --- Doc/reference/datamodel.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 4f81175b157aa9..885ca8c60b059e 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1614,10 +1614,10 @@ Basic customization not considered. When no method returns any value other than NotImplemented, comparisons raise - a :exc:`TypeError`. However, the `==` and `!=` operators will not raise an - exception in that case, and will instead fall back to `is` and `is not`, - respectively. That way, even though `object().__eq__(object())` returns - NotImplemented, `object() == object()` returns False. + a :exc:`TypeError`. However, the ``==`` and ``!=`` operators will not raise an + exception in that case, and will instead fall back to ``is`` and ``is not``, + respectively. That way, even though ``object().__eq__(object())`` returns + NotImplemented, ``object() == object()`` returns False. .. method:: object.__hash__(self) From 71182cdb3905fdcc07089e60cbbcb5828293e5da Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Tue, 2 Jan 2024 01:24:11 +0100 Subject: [PATCH 3/6] Rephrase following feedback --- Doc/reference/datamodel.rst | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 885ca8c60b059e..4d3c9b3559823a 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1613,11 +1613,9 @@ Basic customization the left operand's method has priority. Virtual subclassing is not considered. - When no method returns any value other than NotImplemented, comparisons raise - a :exc:`TypeError`. However, the ``==`` and ``!=`` operators will not raise an - exception in that case, and will instead fall back to ``is`` and ``is not``, - respectively. That way, even though ``object().__eq__(object())`` returns - NotImplemented, ``object() == object()`` returns False. + When no appropriate method returns any value other than ``NotImplemented``, the + ``==`` and ``!=`` operators will fall back to ``is`` and ``is not``, respectively. + The other comparison operators raise a :exc:`TypeError` in that case. .. method:: object.__hash__(self) From 7aa224a599d42125d042cd8f71b1630d5fea037a Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Tue, 2 Jan 2024 02:21:40 +0100 Subject: [PATCH 4/6] Shorten again --- Doc/reference/datamodel.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 4d3c9b3559823a..abd771e9045009 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1615,7 +1615,6 @@ Basic customization When no appropriate method returns any value other than ``NotImplemented``, the ``==`` and ``!=`` operators will fall back to ``is`` and ``is not``, respectively. - The other comparison operators raise a :exc:`TypeError` in that case. .. method:: object.__hash__(self) From 6055434c05291e74ca572e57b28e42da151117bd Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:39:45 +0100 Subject: [PATCH 5/6] Use data role and forgotten "the" --- Doc/reference/datamodel.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 0ef9d5b0fcb23d..af7b0651ef6b42 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1812,13 +1812,13 @@ Basic customization rather, :meth:`__lt__` and :meth:`__gt__` are each other's reflection, :meth:`__le__` and :meth:`__ge__` are each other's reflection, and :meth:`__eq__` and :meth:`__ne__` are their own reflection. - If the operands are of different types, and right operand's type is + If the operands are of different types, and the right operand's type is a direct or indirect subclass of the left operand's type, the reflected method of the right operand has priority, otherwise the left operand's method has priority. Virtual subclassing is not considered. - When no appropriate method returns any value other than ``NotImplemented``, the + When no appropriate method returns any value other than :data:`!NotImplemented`, the ``==`` and ``!=`` operators will fall back to ``is`` and ``is not``, respectively. .. method:: object.__hash__(self) From 820c5389356f5f29bacba6553c647dacc3aa23b0 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sun, 3 Mar 2024 01:39:18 +0100 Subject: [PATCH 6/6] Restore NotImplemented link --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index af7b0651ef6b42..cb6792b609c003 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1818,7 +1818,7 @@ Basic customization the left operand's method has priority. Virtual subclassing is not considered. - When no appropriate method returns any value other than :data:`!NotImplemented`, the + When no appropriate method returns any value other than :data:`NotImplemented`, the ``==`` and ``!=`` operators will fall back to ``is`` and ``is not``, respectively. .. method:: object.__hash__(self)