Skip to content

Commit b004943

Browse files
committed
(3.4) Issue22780: reword NotImplemented docs to emphasise should
1 parent e823933 commit b004943

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

Doc/library/constants.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,24 @@ A small number of constants live in the built-in namespace. They are:
2626

2727
.. data:: NotImplemented
2828

29-
Special value which can be returned by the "rich comparison" special methods
30-
(:meth:`__eq__`, :meth:`__lt__`, and friends), to indicate that the comparison
31-
is not implemented with respect to the other type.
29+
Special value which should be returned by the binary special methods
30+
(e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
31+
etc.) to indicate that the operation is not implemented with respect to
32+
the other type; may be returned by the in-place binary special methods
33+
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
34+
Its truth value is true.
35+
36+
.. note::
37+
38+
When ``NotImplemented`` is returned, the interpreter will then try the
39+
reflected operation on the other type, or some other fallback, depending
40+
on the operator. If all attempted operations return ``NotImplemented``, the
41+
interpreter will raise an appropriate exception.
42+
43+
See
44+
:ref:`implementing-the-arithmetic-operations`
45+
for more details.
46+
3247

3348

3449
.. data:: Ellipsis

Doc/library/numbers.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ those. You can add ``MyFoo`` between :class:`Complex` and
110110
MyFoo.register(Real)
111111

112112

113+
.. _implementing-the-arithmetic-operations:
114+
113115
Implementing the arithmetic operations
114116
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115117

Doc/reference/datamodel.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,16 @@ NotImplemented
154154

155155
This type has a single value. There is a single object with this value. This
156156
object is accessed through the built-in name ``NotImplemented``. Numeric methods
157-
and rich comparison methods may return this value if they do not implement the
157+
and rich comparison methods should return this value if they do not implement the
158158
operation for the operands provided. (The interpreter will then try the
159159
reflected operation, or some other fallback, depending on the operator.) Its
160160
truth value is true.
161161

162+
See
163+
:ref:`implementing-the-arithmetic-operations`
164+
for more details.
165+
166+
162167
Ellipsis
163168
.. index:: object: Ellipsis
164169

0 commit comments

Comments
 (0)