From d9bb67bec0e11de726062a559047a459758a96ec Mon Sep 17 00:00:00 2001 From: sai Date: Sat, 31 Oct 2026 19:53:17 +0530 Subject: [PATCH 1/6] Docs: simplify subtype notation in numbers.rst --- Doc/library/numbers.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 0ed24b4e6c5225..0b4f1fc7685967 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -146,8 +146,8 @@ There are 5 different cases for a mixed-type operation on subclasses of :class:`Complex`. I'll refer to all of the above code that doesn't refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as "boilerplate". ``a`` will be an instance of ``A``, which is a subtype -of :class:`Complex` (``a : A <: Complex``), and ``b : B <: -Complex``. I'll consider ``a + b``: +of :class:`Complex`, and ``b`` will be an instance of ``B``. +I'll consider ``a + b``: 1. If ``A`` defines an :meth:`~object.__add__` which accepts ``b``, all is well. @@ -162,13 +162,14 @@ Complex``. I'll consider ``a + b``: 4. If it falls back to the boilerplate, there are no more possible methods to try, so this is where the default implementation should live. -5. If ``B <: A``, Python tries ``B.__radd__`` before +5. If ``B`` is a subtype of ``A``, Python tries ``B.__radd__`` before ``A.__add__``. This is ok, because it was implemented with knowledge of ``A``, so it can handle those instances before delegating to :class:`Complex`. -If ``A <: Complex`` and ``B <: Real`` without sharing any other knowledge, -then the appropriate shared operation is the one involving the built +If ``A`` is a subtype of :class:`Complex` and ``B`` is a subtype of +:class:`Real` without sharing any other knowledge, then the appropriate +shared operation is the one involving the built in :class:`complex`, and both :meth:`~object.__radd__` s land there, so ``a+b == b+a``. From a8fb47ddc7fd4f5de071435088381aca568598e3 Mon Sep 17 00:00:00 2001 From: sai Date: Sat, 31 Oct 2026 20:11:38 +0530 Subject: [PATCH 2/6] Docs: preserve operand subtype relationship --- Doc/library/numbers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 0b4f1fc7685967..1b73f237e2929c 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -146,8 +146,8 @@ There are 5 different cases for a mixed-type operation on subclasses of :class:`Complex`. I'll refer to all of the above code that doesn't refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as "boilerplate". ``a`` will be an instance of ``A``, which is a subtype -of :class:`Complex`, and ``b`` will be an instance of ``B``. -I'll consider ``a + b``: +of :class:`Complex`, and ``b`` will be an instance of ``B``, +which is also a subtype of :class:`Complex`. I'll consider ``a + b``: 1. If ``A`` defines an :meth:`~object.__add__` which accepts ``b``, all is well. From f20281bfb7a2eb7a21dc34254a35ba104bf87049 Mon Sep 17 00:00:00 2001 From: sai Date: Sat, 31 Oct 2026 20:48:31 +0530 Subject: [PATCH 3/6] Docs: improve subtype explanation in numbers.rst --- Doc/library/numbers.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 1b73f237e2929c..53611174d799a8 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -144,10 +144,11 @@ defined as:: There are 5 different cases for a mixed-type operation on subclasses of :class:`Complex`. I'll refer to all of the above code that doesn't -refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as -"boilerplate". ``a`` will be an instance of ``A``, which is a subtype -of :class:`Complex`, and ``b`` will be an instance of ``B``, -which is also a subtype of :class:`Complex`. I'll consider ``a + b``: +refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as "boilerplate". + +Let ``a`` be an instance of ``A`` and ``b`` be an instance of ``B``, +where both ``A`` and ``B`` are subtypes of :class:`Complex`. +I'll consider ``a + b``: 1. If ``A`` defines an :meth:`~object.__add__` which accepts ``b``, all is well. From 446ab077dbcde5c6925971d367a38805e404c7c2 Mon Sep 17 00:00:00 2001 From: sai Date: Sat, 31 Oct 2026 21:03:27 +0530 Subject: [PATCH 4/6] Docs: address review feedback --- Doc/library/numbers.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 53611174d799a8..a721e80acf9b37 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -146,8 +146,8 @@ There are 5 different cases for a mixed-type operation on subclasses of :class:`Complex`. I'll refer to all of the above code that doesn't refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as "boilerplate". -Let ``a`` be an instance of ``A`` and ``b`` be an instance of ``B``, -where both ``A`` and ``B`` are subtypes of :class:`Complex`. +In this description, ``a`` is an instance of ``A`` and ``b`` is an +instance of ``B``, where ``A`` and ``B`` are both subtypes of :class:`Complex`. I'll consider ``a + b``: 1. If ``A`` defines an :meth:`~object.__add__` which accepts ``b``, all is From cc02c00ac9e5eb2ba7bd9c084a68f7197520b54c Mon Sep 17 00:00:00 2001 From: sai Date: Sat, 31 Oct 2026 21:07:04 +0530 Subject: [PATCH 5/6] Docs: address review feedback --- Doc/library/numbers.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index a721e80acf9b37..50c13cbcda365e 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -143,12 +143,12 @@ defined as:: There are 5 different cases for a mixed-type operation on subclasses -of :class:`Complex`. I'll refer to all of the above code that doesn't -refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as "boilerplate". +of :class:`Complex`. All of the above code that doesn't refer to +``MyIntegral`` and ``OtherTypeIKnowAbout`` is referred to as "boilerplate". In this description, ``a`` is an instance of ``A`` and ``b`` is an instance of ``B``, where ``A`` and ``B`` are both subtypes of :class:`Complex`. -I'll consider ``a + b``: +Consider ``a + b``: 1. If ``A`` defines an :meth:`~object.__add__` which accepts ``b``, all is well. From 9a1da237975f25830a1cac5ced187dcefa84425d Mon Sep 17 00:00:00 2001 From: sai Date: Sat, 31 Oct 2026 22:48:15 +0530 Subject: [PATCH 6/6] Fix numeric ABCs heading capitalization --- Doc/library/numbers.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/numbers.rst b/Doc/library/numbers.rst index 50c13cbcda365e..a0ef2fcc37ad4e 100644 --- a/Doc/library/numbers.rst +++ b/Doc/library/numbers.rst @@ -93,7 +93,7 @@ them to the same values. This may be subtle if there are two different extensions of the real numbers. See also :ref:`numeric-hash`. -Adding More Numeric ABCs +Adding more numeric ABCs ~~~~~~~~~~~~~~~~~~~~~~~~ There are, of course, more possible ABCs for numbers, and this would