Skip to content

Commit 683fca8

Browse files
saiofflnedbat
andauthored
Docs: gh-161005: simplify subtype notation in numbers.rst (#161006)
* Docs: simplify subtype notation in numbers.rst * Docs: preserve operand subtype relationship * Docs: improve subtype explanation in numbers.rst * Docs: address review feedback * Docs: address review feedback * Fix numeric ABCs heading capitalization --------- Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
1 parent 90dc8bd commit 683fca8

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎Doc/library/numbers.rst‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ them to the same values. This may be subtle if there are two different
9393
extensions of the real numbers. See also :ref:`numeric-hash`.
9494

9595

96-
Adding More Numeric ABCs
96+
Adding more numeric ABCs
9797
~~~~~~~~~~~~~~~~~~~~~~~~
9898

9999
There are, of course, more possible ABCs for numbers, and this would
@@ -143,11 +143,12 @@ defined as::
143143

144144

145145
There are 5 different cases for a mixed-type operation on subclasses
146-
of :class:`Complex`. I'll refer to all of the above code that doesn't
147-
refer to ``MyIntegral`` and ``OtherTypeIKnowAbout`` as
148-
"boilerplate". ``a`` will be an instance of ``A``, which is a subtype
149-
of :class:`Complex` (``a : A <: Complex``), and ``b : B <:
150-
Complex``. I'll consider ``a + b``:
146+
of :class:`Complex`. All of the above code that doesn't refer to
147+
``MyIntegral`` and ``OtherTypeIKnowAbout`` is referred to as "boilerplate".
148+
149+
In this description, ``a`` is an instance of ``A`` and ``b`` is an
150+
instance of ``B``, where ``A`` and ``B`` are both subtypes of :class:`Complex`.
151+
Consider ``a + b``:
151152

152153
1. If ``A`` defines an :meth:`~object.__add__` which accepts ``b``, all is
153154
well.
@@ -162,13 +163,14 @@ Complex``. I'll consider ``a + b``:
162163
4. If it falls back to the boilerplate, there are no more possible
163164
methods to try, so this is where the default implementation
164165
should live.
165-
5. If ``B <: A``, Python tries ``B.__radd__`` before
166+
5. If ``B`` is a subtype of ``A``, Python tries ``B.__radd__`` before
166167
``A.__add__``. This is ok, because it was implemented with
167168
knowledge of ``A``, so it can handle those instances before
168169
delegating to :class:`Complex`.
169170

170-
If ``A <: Complex`` and ``B <: Real`` without sharing any other knowledge,
171-
then the appropriate shared operation is the one involving the built
171+
If ``A`` is a subtype of :class:`Complex` and ``B`` is a subtype of
172+
:class:`Real` without sharing any other knowledge, then the appropriate
173+
shared operation is the one involving the built
172174
in :class:`complex`, and both :meth:`~object.__radd__` s land there, so ``a+b
173175
== b+a``.
174176

0 commit comments

Comments
 (0)