Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4efc13

Browse files
[3.11] Docs: mark up NotImplemented using the :data: role throughout the docs (GH-116135) (#116148)
(cherry picked from commit dbe44f1) Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 8643cfd commit f4efc13

16 files changed

Lines changed: 39 additions & 39 deletions

Doc/library/abc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ a helper class :class:`ABC` to alternatively define ABCs through inheritance:
101101
subclass of the ABC. (This class method is called from the
102102
:meth:`~class.__subclasscheck__` method of the ABC.)
103103

104-
This method should return ``True``, ``False`` or ``NotImplemented``. If
104+
This method should return ``True``, ``False`` or :data:`NotImplemented`. If
105105
it returns ``True``, the *subclass* is considered a subclass of this ABC.
106106
If it returns ``False``, the *subclass* is not considered a subclass of
107107
this ABC, even if it would normally be one. If it returns
108-
``NotImplemented``, the subclass check is continued with the usual
108+
:data:`!NotImplemented`, the subclass check is continued with the usual
109109
mechanism.
110110

111111
.. XXX explain the "usual mechanism"

Doc/library/constants.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ A small number of constants live in the built-in namespace. They are:
3333
the other type; may be returned by the in-place binary special methods
3434
(e.g. :meth:`~object.__imul__`, :meth:`~object.__iand__`, etc.) for the same purpose.
3535
It should not be evaluated in a boolean context.
36-
``NotImplemented`` is the sole instance of the :data:`types.NotImplementedType` type.
36+
:data:`!NotImplemented` is the sole instance of the :data:`types.NotImplementedType` type.
3737

3838
.. note::
3939

40-
When a binary (or in-place) method returns ``NotImplemented`` the
40+
When a binary (or in-place) method returns :data:`!NotImplemented` the
4141
interpreter will try the reflected operation on the other type (or some
4242
other fallback, depending on the operator). If all attempts return
43-
``NotImplemented``, the interpreter will raise an appropriate exception.
44-
Incorrectly returning ``NotImplemented`` will result in a misleading
45-
error message or the ``NotImplemented`` value being returned to Python code.
43+
:data:`!NotImplemented`, the interpreter will raise an appropriate exception.
44+
Incorrectly returning :data:`!NotImplemented` will result in a misleading
45+
error message or the :data:`!NotImplemented` value being returned to Python code.
4646

4747
See :ref:`implementing-the-arithmetic-operations` for examples.
4848

4949
.. note::
5050

51-
``NotImplementedError`` and ``NotImplemented`` are not interchangeable,
51+
``NotImplementedError`` and :data:`!NotImplemented` are not interchangeable,
5252
even though they have similar names and purposes.
5353
See :exc:`NotImplementedError` for details on when to use it.
5454

5555
.. versionchanged:: 3.9
56-
Evaluating ``NotImplemented`` in a boolean context is deprecated. While
56+
Evaluating :data:`!NotImplemented` in a boolean context is deprecated. While
5757
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
5858
It will raise a :exc:`TypeError` in a future version of Python.
5959

Doc/library/exceptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ The following exceptions are the exceptions that are usually raised.
335335

336336
.. note::
337337

338-
``NotImplementedError`` and ``NotImplemented`` are not interchangeable,
338+
``NotImplementedError`` and :data:`NotImplemented` are not interchangeable,
339339
even though they have similar names and purposes. See
340-
:data:`NotImplemented` for details on when to use it.
340+
:data:`!NotImplemented` for details on when to use it.
341341

342342
.. exception:: OSError([arg])
343343
OSError(errno, strerror[, filename[, winerror[, filename2]]])

Doc/library/importlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ ABC hierarchy::
329329
when invalidating the caches of all finders on :data:`sys.meta_path`.
330330

331331
.. versionchanged:: 3.4
332-
Returns ``None`` when called instead of ``NotImplemented``.
332+
Returns ``None`` when called instead of :data:`NotImplemented`.
333333

334334

335335
.. class:: PathEntryFinder

Doc/library/numbers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Complex``. I'll consider ``a + b``:
166166
2. If ``A`` falls back to the boilerplate code, and it were to
167167
return a value from :meth:`~object.__add__`, we'd miss the possibility
168168
that ``B`` defines a more intelligent :meth:`~object.__radd__`, so the
169-
boilerplate should return :const:`NotImplemented` from
169+
boilerplate should return :data:`NotImplemented` from
170170
:meth:`!__add__`. (Or ``A`` may not implement :meth:`!__add__` at
171171
all.)
172172
3. Then ``B``'s :meth:`~object.__radd__` gets a chance. If it accepts

Doc/library/pickle.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
373373
Special reducer that can be defined in :class:`Pickler` subclasses. This
374374
method has priority over any reducer in the :attr:`dispatch_table`. It
375375
should conform to the same interface as a :meth:`~object.__reduce__` method, and
376-
can optionally return ``NotImplemented`` to fallback on
376+
can optionally return :data:`NotImplemented` to fallback on
377377
:attr:`dispatch_table`-registered reducers to pickle ``obj``.
378378

379379
For a detailed example, see :ref:`reducer_override`.
@@ -495,7 +495,7 @@ What can be pickled and unpickled?
495495
The following types can be pickled:
496496

497497
* built-in constants (``None``, ``True``, ``False``, ``Ellipsis``, and
498-
``NotImplemented``);
498+
:data:`NotImplemented`);
499499

500500
* integers, floating-point numbers, complex numbers;
501501

@@ -897,7 +897,7 @@ functions and classes.
897897
For those cases, it is possible to subclass from the :class:`Pickler` class and
898898
implement a :meth:`~Pickler.reducer_override` method. This method can return an
899899
arbitrary reduction tuple (see :meth:`~object.__reduce__`). It can alternatively return
900-
``NotImplemented`` to fallback to the traditional behavior.
900+
:data:`NotImplemented` to fallback to the traditional behavior.
901901

902902
If both the :attr:`~Pickler.dispatch_table` and
903903
:meth:`~Pickler.reducer_override` are defined, then

Doc/library/stdtypes.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5392,10 +5392,10 @@ The NotImplemented Object
53925392

53935393
This object is returned from comparisons and binary operations when they are
53945394
asked to operate on types they don't support. See :ref:`comparisons` for more
5395-
information. There is exactly one ``NotImplemented`` object.
5396-
``type(NotImplemented)()`` produces the singleton instance.
5395+
information. There is exactly one :data:`NotImplemented` object.
5396+
:code:`type(NotImplemented)()` produces the singleton instance.
53975397

5398-
It is written as ``NotImplemented``.
5398+
It is written as :code:`NotImplemented`.
53995399

54005400

54015401
.. _bltin-boolean-values:

Doc/library/unittest.mock.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,10 +2092,10 @@ to change the default.
20922092

20932093
Methods and their defaults:
20942094

2095-
* ``__lt__``: ``NotImplemented``
2096-
* ``__gt__``: ``NotImplemented``
2097-
* ``__le__``: ``NotImplemented``
2098-
* ``__ge__``: ``NotImplemented``
2095+
* ``__lt__``: :data:`NotImplemented`
2096+
* ``__gt__``: :data:`!NotImplemented`
2097+
* ``__le__``: :data:`!NotImplemented`
2098+
* ``__ge__``: :data:`!NotImplemented`
20992099
* ``__int__``: ``1``
21002100
* ``__contains__``: ``False``
21012101
* ``__len__``: ``0``

Doc/reference/datamodel.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ NotImplemented
159159
.. index:: pair: object; NotImplemented
160160

161161
This type has a single value. There is a single object with this value. This
162-
object is accessed through the built-in name ``NotImplemented``. Numeric methods
162+
object is accessed through the built-in name :data:`NotImplemented`. Numeric methods
163163
and rich comparison methods should return this value if they do not implement the
164164
operation for the operands provided. (The interpreter will then try the
165165
reflected operation, or some other fallback, depending on the operator.) It
@@ -170,7 +170,7 @@ See
170170
for more details.
171171

172172
.. versionchanged:: 3.9
173-
Evaluating ``NotImplemented`` in a boolean context is deprecated. While
173+
Evaluating :data:`NotImplemented` in a boolean context is deprecated. While
174174
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
175175
It will raise a :exc:`TypeError` in a future version of Python.
176176

@@ -1763,18 +1763,18 @@ Basic customization
17631763
``x.__ne__(y)``, ``x>y`` calls ``x.__gt__(y)``, and ``x>=y`` calls
17641764
``x.__ge__(y)``.
17651765

1766-
A rich comparison method may return the singleton ``NotImplemented`` if it does
1766+
A rich comparison method may return the singleton :data:`NotImplemented` if it does
17671767
not implement the operation for a given pair of arguments. By convention,
17681768
``False`` and ``True`` are returned for a successful comparison. However, these
17691769
methods can return any value, so if the comparison operator is used in a Boolean
17701770
context (e.g., in the condition of an ``if`` statement), Python will call
17711771
:func:`bool` on the value to determine if the result is true or false.
17721772

17731773
By default, ``object`` implements :meth:`__eq__` by using ``is``, returning
1774-
``NotImplemented`` in the case of a false comparison:
1774+
:data:`NotImplemented` in the case of a false comparison:
17751775
``True if x is y else NotImplemented``. For :meth:`__ne__`, by default it
17761776
delegates to :meth:`__eq__` and inverts the result unless it is
1777-
``NotImplemented``. There are no other implied relationships among the
1777+
:data:`!NotImplemented`. There are no other implied relationships among the
17781778
comparison operators or default implementations; for example, the truth of
17791779
``(x<y or x==y)`` does not imply ``x<=y``. To automatically generate ordering
17801780
operations from a single root operation, see :func:`functools.total_ordering`.
@@ -2800,7 +2800,7 @@ through the object's keys; for sequences, it should iterate through the values.
28002800
Called to implement :func:`operator.length_hint`. Should return an estimated
28012801
length for the object (which may be greater or less than the actual length).
28022802
The length must be an integer ``>=`` 0. The return value may also be
2803-
:const:`NotImplemented`, which is treated the same as if the
2803+
:data:`NotImplemented`, which is treated the same as if the
28042804
``__length_hint__`` method didn't exist at all. This method is purely an
28052805
optimization and is never required for correctness.
28062806

@@ -2952,7 +2952,7 @@ left undefined.
29522952
function is to be supported.
29532953

29542954
If one of those methods does not support the operation with the supplied
2955-
arguments, it should return ``NotImplemented``.
2955+
arguments, it should return :data:`NotImplemented`.
29562956

29572957

29582958
.. method:: object.__radd__(self, other)
@@ -2982,7 +2982,7 @@ left undefined.
29822982
types. [#]_ For instance, to evaluate the expression ``x - y``, where *y* is
29832983
an instance of a class that has an :meth:`__rsub__` method,
29842984
``type(y).__rsub__(y, x)`` is called if ``type(x).__sub__(x, y)`` returns
2985-
*NotImplemented*.
2985+
:data:`NotImplemented`.
29862986

29872987
.. index:: pair: built-in function; pow
29882988

@@ -3428,7 +3428,7 @@ An example of an asynchronous context manager class::
34283428
the behavior that ``None`` is not callable.
34293429
34303430
.. [#] "Does not support" here means that the class has no such method, or
3431-
the method returns ``NotImplemented``. Do not set the method to
3431+
the method returns :data:`NotImplemented`. Do not set the method to
34323432
``None`` if you want to force fallback to the right operand's reflected
34333433
method—that will instead have the opposite effect of explicitly
34343434
*blocking* such fallback.

Doc/reference/expressions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ built-in types.
15221522
``x == x`` are all false, while ``x != x`` is true. This behavior is
15231523
compliant with IEEE 754.
15241524

1525-
* ``None`` and ``NotImplemented`` are singletons. :PEP:`8` advises that
1525+
* ``None`` and :data:`NotImplemented` are singletons. :PEP:`8` advises that
15261526
comparisons for singletons should always be done with ``is`` or ``is not``,
15271527
never the equality operators.
15281528

0 commit comments

Comments
 (0)