Skip to content

Commit 40d7652

Browse files
bpo-42182: stdtypes doc - update and fix links to several dunder methods (GH-27384)
(cherry picked from commit 8c74713) Co-authored-by: andrei kulakov <[email protected]>
1 parent fb8aad1 commit 40d7652

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Doc/library/stdtypes.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,14 @@ operators are only defined where they make sense; for example, they raise a
178178
single: __ge__() (instance method)
179179

180180
Non-identical instances of a class normally compare as non-equal unless the
181-
class defines the :meth:`__eq__` method.
181+
class defines the :meth:`~object.__eq__` method.
182182

183183
Instances of a class cannot be ordered with respect to other instances of the
184184
same class, or other types of object, unless the class defines enough of the
185-
methods :meth:`__lt__`, :meth:`__le__`, :meth:`__gt__`, and :meth:`__ge__` (in
186-
general, :meth:`__lt__` and :meth:`__eq__` are sufficient, if you want the
187-
conventional meanings of the comparison operators).
185+
methods :meth:`~object.__lt__`, :meth:`~object.__le__`, :meth:`~object.__gt__`, and
186+
:meth:`~object.__ge__` (in general, :meth:`~object.__lt__` and
187+
:meth:`~object.__eq__` are sufficient, if you want the conventional meanings of the
188+
comparison operators).
188189

189190
The behavior of the :keyword:`is` and :keyword:`is not` operators cannot be
190191
customized; also they can be applied to any two objects and never raise an
@@ -639,7 +640,7 @@ Hashing of numeric types
639640
------------------------
640641

641642
For numbers ``x`` and ``y``, possibly of different types, it's a requirement
642-
that ``hash(x) == hash(y)`` whenever ``x == y`` (see the :meth:`__hash__`
643+
that ``hash(x) == hash(y)`` whenever ``x == y`` (see the :meth:`~object.__hash__`
643644
method documentation for more details). For ease of implementation and
644645
efficiency across a variety of numeric types (including :class:`int`,
645646
:class:`float`, :class:`decimal.Decimal` and :class:`fractions.Fraction`)
@@ -1275,7 +1276,7 @@ loops.
12751276
range(start, stop[, step])
12761277

12771278
The arguments to the range constructor must be integers (either built-in
1278-
:class:`int` or any object that implements the ``__index__`` special
1279+
:class:`int` or any object that implements the :meth:`~object.__index__` special
12791280
method). If the *step* argument is omitted, it defaults to ``1``.
12801281
If the *start* argument is omitted, it defaults to ``0``.
12811282
If *step* is zero, :exc:`ValueError` is raised.
@@ -4719,9 +4720,9 @@ their implementation of the context management protocol. See the
47194720
Python's :term:`generator`\s and the :class:`contextlib.contextmanager` decorator
47204721
provide a convenient way to implement these protocols. If a generator function is
47214722
decorated with the :class:`contextlib.contextmanager` decorator, it will return a
4722-
context manager implementing the necessary :meth:`__enter__` and
4723-
:meth:`__exit__` methods, rather than the iterator produced by an undecorated
4724-
generator function.
4723+
context manager implementing the necessary :meth:`~contextmanager.__enter__` and
4724+
:meth:`~contextmanager.__exit__` methods, rather than the iterator produced by an
4725+
undecorated generator function.
47254726

47264727
Note that there is no specific slot for any of these methods in the type
47274728
structure for Python objects in the Python/C API. Extension types wanting to

0 commit comments

Comments
 (0)