Skip to content

Commit f600878

Browse files
[3.11] gh-101100: Fix Sphinx nitpicks in library/functions.rst (GH-112669) (#112698)
gh-101100: Fix Sphinx nitpicks in `library/functions.rst` (GH-112669) (cherry picked from commit cda7379) Co-authored-by: Alex Waygood <[email protected]>
1 parent 7e89dd9 commit f600878

File tree

2 files changed

+67
-47
lines changed

2 files changed

+67
-47
lines changed

Doc/library/functions.rst

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ are always available. They are listed here in alphabetical order.
5757
.. function:: abs(x)
5858

5959
Return the absolute value of a number. The argument may be an
60-
integer, a floating point number, or an object implementing :meth:`__abs__`.
60+
integer, a floating point number, or an object implementing
61+
:meth:`~object.__abs__`.
6162
If the argument is a complex number, its magnitude is returned.
6263

6364

@@ -235,7 +236,7 @@ are always available. They are listed here in alphabetical order.
235236
:const:`False` if not. If this returns ``True``, it is still possible that a
236237
call fails, but if it is ``False``, calling *object* will never succeed.
237238
Note that classes are callable (calling a class returns a new instance);
238-
instances are callable if their class has a :meth:`__call__` method.
239+
instances are callable if their class has a :meth:`~object.__call__` method.
239240

240241
.. versionadded:: 3.2
241242
This function was first removed in Python 3.0 and then brought back
@@ -432,15 +433,18 @@ are always available. They are listed here in alphabetical order.
432433
Without arguments, return the list of names in the current local scope. With an
433434
argument, attempt to return a list of valid attributes for that object.
434435

435-
If the object has a method named :meth:`__dir__`, this method will be called and
436+
If the object has a method named :meth:`~object.__dir__`,
437+
this method will be called and
436438
must return the list of attributes. This allows objects that implement a custom
437-
:func:`__getattr__` or :func:`__getattribute__` function to customize the way
439+
:func:`~object.__getattr__` or :func:`~object.__getattribute__` function
440+
to customize the way
438441
:func:`dir` reports their attributes.
439442

440-
If the object does not provide :meth:`__dir__`, the function tries its best to
441-
gather information from the object's :attr:`~object.__dict__` attribute, if defined, and
443+
If the object does not provide :meth:`~object.__dir__`,
444+
the function tries its best to gather information from the object's
445+
:attr:`~object.__dict__` attribute, if defined, and
442446
from its type object. The resulting list is not necessarily complete and may
443-
be inaccurate when the object has a custom :func:`__getattr__`.
447+
be inaccurate when the object has a custom :func:`~object.__getattr__`.
444448

445449
The default :func:`dir` mechanism behaves differently with different types of
446450
objects, as it attempts to produce the most relevant, rather than complete,
@@ -663,7 +667,7 @@ are always available. They are listed here in alphabetical order.
663667
sign: "+" | "-"
664668
infinity: "Infinity" | "inf"
665669
nan: "nan"
666-
digitpart: `digit` (["_"] `digit`)*
670+
digitpart: `!digit` (["_"] `!digit`)*
667671
number: [`digitpart`] "." `digitpart` | `digitpart` ["."]
668672
exponent: ("e" | "E") ["+" | "-"] `digitpart`
669673
floatnumber: number [`exponent`]
@@ -726,8 +730,8 @@ are always available. They are listed here in alphabetical order.
726730

727731
A call to ``format(value, format_spec)`` is translated to
728732
``type(value).__format__(value, format_spec)`` which bypasses the instance
729-
dictionary when searching for the value's :meth:`__format__` method. A
730-
:exc:`TypeError` exception is raised if the method search reaches
733+
dictionary when searching for the value's :meth:`~object.__format__` method.
734+
A :exc:`TypeError` exception is raised if the method search reaches
731735
:mod:`object` and the *format_spec* is non-empty, or if either the
732736
*format_spec* or the return value are not strings.
733737

@@ -791,9 +795,9 @@ are always available. They are listed here in alphabetical order.
791795

792796
.. note::
793797

794-
For objects with custom :meth:`__hash__` methods, note that :func:`hash`
798+
For objects with custom :meth:`~object.__hash__` methods,
799+
note that :func:`hash`
795800
truncates the return value based on the bit width of the host machine.
796-
See :meth:`__hash__ <object.__hash__>` for details.
797801

798802
.. function:: help()
799803
help(request)
@@ -981,7 +985,8 @@ are always available. They are listed here in alphabetical order.
981985
Return an :term:`iterator` object. The first argument is interpreted very
982986
differently depending on the presence of the second argument. Without a
983987
second argument, *object* must be a collection object which supports the
984-
:term:`iterable` protocol (the :meth:`__iter__` method), or it must support
988+
:term:`iterable` protocol (the :meth:`~object.__iter__` method),
989+
or it must support
985990
the sequence protocol (the :meth:`~object.__getitem__` method with integer arguments
986991
starting at ``0``). If it does not support either of those protocols,
987992
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
@@ -1499,38 +1504,44 @@ are always available. They are listed here in alphabetical order.
14991504
"""Get the current voltage."""
15001505
return self._voltage
15011506

1502-
The ``@property`` decorator turns the :meth:`voltage` method into a "getter"
1507+
The ``@property`` decorator turns the :meth:`!voltage` method into a "getter"
15031508
for a read-only attribute with the same name, and it sets the docstring for
15041509
*voltage* to "Get the current voltage."
15051510

1506-
A property object has :attr:`~property.getter`, :attr:`~property.setter`,
1507-
and :attr:`~property.deleter` methods usable as decorators that create a
1508-
copy of the property with the corresponding accessor function set to the
1509-
decorated function. This is best explained with an example::
1511+
.. decorator:: property.getter
1512+
.. decorator:: property.setter
1513+
.. decorator:: property.deleter
15101514

1511-
class C:
1512-
def __init__(self):
1513-
self._x = None
1515+
A property object has ``getter``, ``setter``,
1516+
and ``deleter`` methods usable as decorators that create a
1517+
copy of the property with the corresponding accessor function set to the
1518+
decorated function. This is best explained with an example:
15141519

1515-
@property
1516-
def x(self):
1517-
"""I'm the 'x' property."""
1518-
return self._x
1520+
.. testcode::
15191521

1520-
@x.setter
1521-
def x(self, value):
1522-
self._x = value
1522+
class C:
1523+
def __init__(self):
1524+
self._x = None
15231525

1524-
@x.deleter
1525-
def x(self):
1526-
del self._x
1526+
@property
1527+
def x(self):
1528+
"""I'm the 'x' property."""
1529+
return self._x
15271530

1528-
This code is exactly equivalent to the first example. Be sure to give the
1529-
additional functions the same name as the original property (``x`` in this
1530-
case.)
1531+
@x.setter
1532+
def x(self, value):
1533+
self._x = value
15311534

1532-
The returned property object also has the attributes ``fget``, ``fset``, and
1533-
``fdel`` corresponding to the constructor arguments.
1535+
@x.deleter
1536+
def x(self):
1537+
del self._x
1538+
1539+
This code is exactly equivalent to the first example. Be sure to give the
1540+
additional functions the same name as the original property (``x`` in this
1541+
case.)
1542+
1543+
The returned property object also has the attributes ``fget``, ``fset``, and
1544+
``fdel`` corresponding to the constructor arguments.
15341545

15351546
.. versionchanged:: 3.5
15361547
The docstrings of property objects are now writeable.
@@ -1553,17 +1564,18 @@ are always available. They are listed here in alphabetical order.
15531564
representation is a string enclosed in angle brackets that contains the name
15541565
of the type of the object together with additional information often
15551566
including the name and address of the object. A class can control what this
1556-
function returns for its instances by defining a :meth:`__repr__` method.
1567+
function returns for its instances
1568+
by defining a :meth:`~object.__repr__` method.
15571569
If :func:`sys.displayhook` is not accessible, this function will raise
15581570
:exc:`RuntimeError`.
15591571

15601572

15611573
.. function:: reversed(seq)
15621574

15631575
Return a reverse :term:`iterator`. *seq* must be an object which has
1564-
a :meth:`__reversed__` method or supports the sequence protocol (the
1565-
:meth:`__len__` method and the :meth:`~object.__getitem__` method with integer
1566-
arguments starting at ``0``).
1576+
a :meth:`~object.__reversed__` method or supports the sequence protocol (the
1577+
:meth:`~object.__len__` method and the :meth:`~object.__getitem__` method
1578+
with integer arguments starting at ``0``).
15671579

15681580

15691581
.. function:: round(number, ndigits=None)
@@ -1634,13 +1646,21 @@ are always available. They are listed here in alphabetical order.
16341646

16351647
Return a :term:`slice` object representing the set of indices specified by
16361648
``range(start, stop, step)``. The *start* and *step* arguments default to
1637-
``None``. Slice objects have read-only data attributes :attr:`~slice.start`,
1638-
:attr:`~slice.stop`, and :attr:`~slice.step` which merely return the argument
1639-
values (or their default). They have no other explicit functionality;
1640-
however, they are used by NumPy and other third-party packages.
1649+
``None``.
1650+
1651+
.. attribute:: slice.start
1652+
.. attribute:: slice.stop
1653+
.. attribute:: slice.step
1654+
1655+
Slice objects have read-only data attributes :attr:`!start`,
1656+
:attr:`!stop`, and :attr:`!step` which merely return the argument
1657+
values (or their default). They have no other explicit functionality;
1658+
however, they are used by NumPy and other third-party packages.
1659+
16411660
Slice objects are also generated when extended indexing syntax is used. For
16421661
example: ``a[start:stop:step]`` or ``a[start:stop, i]``. See
1643-
:func:`itertools.islice` for an alternate version that returns an iterator.
1662+
:func:`itertools.islice` for an alternate version that returns an
1663+
:term:`iterator`.
16441664

16451665

16461666
.. function:: sorted(iterable, /, *, key=None, reverse=False)
@@ -1800,7 +1820,8 @@ are always available. They are listed here in alphabetical order.
18001820

18011821
Note that :func:`super` is implemented as part of the binding process for
18021822
explicit dotted attribute lookups such as ``super().__getitem__(name)``.
1803-
It does so by implementing its own :meth:`__getattribute__` method for searching
1823+
It does so by implementing its own :meth:`~object.__getattribute__` method
1824+
for searching
18041825
classes in a predictable order that supports cooperative multiple inheritance.
18051826
Accordingly, :func:`super` is undefined for implicit lookups using statements or
18061827
operators such as ``super()[name]``.

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ Doc/library/exceptions.rst
6060
Doc/library/faulthandler.rst
6161
Doc/library/fcntl.rst
6262
Doc/library/ftplib.rst
63-
Doc/library/functions.rst
6463
Doc/library/functools.rst
6564
Doc/library/http.client.rst
6665
Doc/library/http.cookiejar.rst

0 commit comments

Comments
 (0)