From 1de0f20485cdba900f74de91f3d1ccfbfbe8dc14 Mon Sep 17 00:00:00 2001 From: tangyuan0821 Date: Mon, 29 Jun 2026 15:13:22 +0800 Subject: [PATCH 1/4] docs: remove outdated Fraction.__hash__ example, link to numeric-hash --- Doc/library/numbers.rst | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 57b35017072c97..5f91dfe40ae932 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -90,20 +90,8 @@ Notes for type implementers Implementers should be careful to make equal numbers equal and hash them to the same values. This may be subtle if there are two different -extensions of the real numbers. For example, :class:`fractions.Fraction` -implements :func:`hash` as follows:: - - def __hash__(self): - if self.denominator == 1: - # Get integers right. - return hash(self.numerator) - # Expensive check, but definitely correct. - if self == float(self): - return hash(float(self)) - else: - # Use tuple's hash to avoid a high collision rate on - # simple fractions. - return hash((self.numerator, self.denominator)) +extensions of the real numbers. For a hashing scheme that is consistent +across numeric types, see :ref:`numeric-hash`. Adding More Numeric ABCs From 7d47a51fb0dc6c071c87b812594154523b17a746 Mon Sep 17 00:00:00 2001 From: Paper Moon <47830915@qq.com> Date: Mon, 29 Jun 2026 15:22:11 +0800 Subject: [PATCH 2/4] Update Doc/library/numbers.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/numbers.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 5f91dfe40ae932..0ed24b4e6c5225 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -90,8 +90,7 @@ Notes for type implementers Implementers should be careful to make equal numbers equal and hash them to the same values. This may be subtle if there are two different -extensions of the real numbers. For a hashing scheme that is consistent -across numeric types, see :ref:`numeric-hash`. +extensions of the real numbers. See also :ref:`numeric-hash`. Adding More Numeric ABCs From 2f04704fd8521bd76483f7daf84b3492e02c57ee Mon Sep 17 00:00:00 2001 From: tangyuan0821 Date: Mon, 29 Jun 2026 15:26:42 +0800 Subject: [PATCH 3/4] Revert "Update Doc/library/numbers.rst" This reverts commit 7d47a51fb0dc6c071c87b812594154523b17a746. --- Doc/library/numbers.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 0ed24b4e6c5225..5f91dfe40ae932 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -90,7 +90,8 @@ Notes for type implementers Implementers should be careful to make equal numbers equal and hash them to the same values. This may be subtle if there are two different -extensions of the real numbers. See also :ref:`numeric-hash`. +extensions of the real numbers. For a hashing scheme that is consistent +across numeric types, see :ref:`numeric-hash`. Adding More Numeric ABCs From 3609e610c29b2d0f2d2e77b605bc018d8db7d6f5 Mon Sep 17 00:00:00 2001 From: tangyuan0821 Date: Mon, 29 Jun 2026 17:28:18 +0800 Subject: [PATCH 4/4] Apply review suggestion: simplify ref to numeric-hash --- Doc/library/numbers.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 5f91dfe40ae932..0ed24b4e6c5225 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -90,8 +90,7 @@ Notes for type implementers Implementers should be careful to make equal numbers equal and hash them to the same values. This may be subtle if there are two different -extensions of the real numbers. For a hashing scheme that is consistent -across numeric types, see :ref:`numeric-hash`. +extensions of the real numbers. See also :ref:`numeric-hash`. Adding More Numeric ABCs