@@ -57,7 +57,8 @@ are always available. They are listed here in alphabetical order.
57
57
.. function :: abs(x)
58
58
59
59
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__ `.
61
62
If the argument is a complex number, its magnitude is returned.
62
63
63
64
@@ -235,7 +236,7 @@ are always available. They are listed here in alphabetical order.
235
236
:const: `False ` if not. If this returns ``True ``, it is still possible that a
236
237
call fails, but if it is ``False ``, calling *object * will never succeed.
237
238
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.
239
240
240
241
.. versionadded :: 3.2
241
242
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.
432
433
Without arguments, return the list of names in the current local scope. With an
433
434
argument, attempt to return a list of valid attributes for that object.
434
435
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
436
438
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
438
441
:func: `dir ` reports their attributes.
439
442
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
442
446
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__ `.
444
448
445
449
The default :func: `dir ` mechanism behaves differently with different types of
446
450
objects, as it attempts to produce the most relevant, rather than complete,
@@ -664,7 +668,7 @@ are always available. They are listed here in alphabetical order.
664
668
sign: "+" | "-"
665
669
infinity: "Infinity" | "inf"
666
670
nan: "nan"
667
- digitpart: `digit ` (["_"] `digit `)*
671
+ digitpart: `! digit ` (["_"] `! digit `)*
668
672
number: [`digitpart `] "." `digitpart ` | `digitpart ` ["."]
669
673
exponent: ("e" | "E") ["+" | "-"] `digitpart `
670
674
floatnumber: number [`exponent `]
@@ -727,8 +731,8 @@ are always available. They are listed here in alphabetical order.
727
731
728
732
A call to ``format(value, format_spec) `` is translated to
729
733
``type(value).__format__(value, format_spec) `` which bypasses the instance
730
- dictionary when searching for the value's :meth: `__format__ ` method. A
731
- :exc: `TypeError ` exception is raised if the method search reaches
734
+ dictionary when searching for the value's :meth: `~object. __format__ ` method.
735
+ A :exc: `TypeError ` exception is raised if the method search reaches
732
736
:mod: `object ` and the *format_spec * is non-empty, or if either the
733
737
*format_spec * or the return value are not strings.
734
738
@@ -792,9 +796,9 @@ are always available. They are listed here in alphabetical order.
792
796
793
797
.. note ::
794
798
795
- For objects with custom :meth: `__hash__ ` methods, note that :func: `hash `
799
+ For objects with custom :meth: `~object.__hash__ ` methods,
800
+ note that :func: `hash `
796
801
truncates the return value based on the bit width of the host machine.
797
- See :meth: `__hash__ <object.__hash__> ` for details.
798
802
799
803
.. function :: help()
800
804
help(request)
@@ -982,7 +986,8 @@ are always available. They are listed here in alphabetical order.
982
986
Return an :term: `iterator ` object. The first argument is interpreted very
983
987
differently depending on the presence of the second argument. Without a
984
988
second argument, *object * must be a collection object which supports the
985
- :term: `iterable ` protocol (the :meth: `__iter__ ` method), or it must support
989
+ :term: `iterable ` protocol (the :meth: `~object.__iter__ ` method),
990
+ or it must support
986
991
the sequence protocol (the :meth: `~object.__getitem__ ` method with integer arguments
987
992
starting at ``0 ``). If it does not support either of those protocols,
988
993
:exc: `TypeError ` is raised. If the second argument, *sentinel *, is given,
@@ -1500,38 +1505,44 @@ are always available. They are listed here in alphabetical order.
1500
1505
"""Get the current voltage."""
1501
1506
return self._voltage
1502
1507
1503
- The ``@property `` decorator turns the :meth: `voltage ` method into a "getter"
1508
+ The ``@property `` decorator turns the :meth: `! voltage ` method into a "getter"
1504
1509
for a read-only attribute with the same name, and it sets the docstring for
1505
1510
*voltage * to "Get the current voltage."
1506
1511
1507
- A property object has :attr: `~property.getter `, :attr: `~property.setter `,
1508
- and :attr: `~property.deleter ` methods usable as decorators that create a
1509
- copy of the property with the corresponding accessor function set to the
1510
- decorated function. This is best explained with an example::
1512
+ .. decorator :: property.getter
1513
+ .. decorator :: property.setter
1514
+ .. decorator :: property.deleter
1511
1515
1512
- class C:
1513
- def __init__(self):
1514
- self._x = None
1516
+ A property object has ``getter ``, ``setter ``,
1517
+ and ``deleter `` methods usable as decorators that create a
1518
+ copy of the property with the corresponding accessor function set to the
1519
+ decorated function. This is best explained with an example:
1515
1520
1516
- @property
1517
- def x(self):
1518
- """I'm the 'x' property."""
1519
- return self._x
1521
+ .. testcode ::
1520
1522
1521
- @x.setter
1522
- def x (self, value ):
1523
- self._x = value
1523
+ class C:
1524
+ def __init__ (self):
1525
+ self._x = None
1524
1526
1525
- @x.deleter
1526
- def x(self):
1527
- del self._x
1527
+ @property
1528
+ def x(self):
1529
+ """I'm the 'x' property."""
1530
+ return self._x
1528
1531
1529
- This code is exactly equivalent to the first example. Be sure to give the
1530
- additional functions the same name as the original property (`` x `` in this
1531
- case.)
1532
+ @x.setter
1533
+ def x(self, value):
1534
+ self._x = value
1532
1535
1533
- The returned property object also has the attributes ``fget ``, ``fset ``, and
1534
- ``fdel `` corresponding to the constructor arguments.
1536
+ @x.deleter
1537
+ def x(self):
1538
+ del self._x
1539
+
1540
+ This code is exactly equivalent to the first example. Be sure to give the
1541
+ additional functions the same name as the original property (``x `` in this
1542
+ case.)
1543
+
1544
+ The returned property object also has the attributes ``fget ``, ``fset ``, and
1545
+ ``fdel `` corresponding to the constructor arguments.
1535
1546
1536
1547
.. versionchanged :: 3.5
1537
1548
The docstrings of property objects are now writeable.
@@ -1554,17 +1565,18 @@ are always available. They are listed here in alphabetical order.
1554
1565
representation is a string enclosed in angle brackets that contains the name
1555
1566
of the type of the object together with additional information often
1556
1567
including the name and address of the object. A class can control what this
1557
- function returns for its instances by defining a :meth: `__repr__ ` method.
1568
+ function returns for its instances
1569
+ by defining a :meth: `~object.__repr__ ` method.
1558
1570
If :func: `sys.displayhook ` is not accessible, this function will raise
1559
1571
:exc: `RuntimeError `.
1560
1572
1561
1573
1562
1574
.. function :: reversed(seq)
1563
1575
1564
1576
Return a reverse :term: `iterator `. *seq * must be an object which has
1565
- a :meth: `__reversed__ ` method or supports the sequence protocol (the
1566
- :meth: `__len__ ` method and the :meth: `~object.__getitem__ ` method with integer
1567
- arguments starting at ``0 ``).
1577
+ a :meth: `~object. __reversed__ ` method or supports the sequence protocol (the
1578
+ :meth: `~object. __len__ ` method and the :meth: `~object.__getitem__ ` method
1579
+ with integer arguments starting at ``0 ``).
1568
1580
1569
1581
1570
1582
.. function :: round(number, ndigits=None)
@@ -1635,13 +1647,21 @@ are always available. They are listed here in alphabetical order.
1635
1647
1636
1648
Return a :term: `slice ` object representing the set of indices specified by
1637
1649
``range(start, stop, step) ``. The *start * and *step * arguments default to
1638
- ``None ``. Slice objects have read-only data attributes :attr: `~slice.start `,
1639
- :attr: `~slice.stop `, and :attr: `~slice.step ` which merely return the argument
1640
- values (or their default). They have no other explicit functionality;
1641
- however, they are used by NumPy and other third-party packages.
1650
+ ``None ``.
1651
+
1652
+ .. attribute :: slice.start
1653
+ .. attribute :: slice.stop
1654
+ .. attribute :: slice.step
1655
+
1656
+ Slice objects have read-only data attributes :attr: `!start `,
1657
+ :attr: `!stop `, and :attr: `!step ` which merely return the argument
1658
+ values (or their default). They have no other explicit functionality;
1659
+ however, they are used by NumPy and other third-party packages.
1660
+
1642
1661
Slice objects are also generated when extended indexing syntax is used. For
1643
1662
example: ``a[start:stop:step] `` or ``a[start:stop, i] ``. See
1644
- :func: `itertools.islice ` for an alternate version that returns an iterator.
1663
+ :func: `itertools.islice ` for an alternate version that returns an
1664
+ :term: `iterator `.
1645
1665
1646
1666
.. versionchanged :: 3.12
1647
1667
Slice objects are now :term: `hashable ` (provided :attr: `~slice.start `,
@@ -1808,7 +1828,8 @@ are always available. They are listed here in alphabetical order.
1808
1828
1809
1829
Note that :func: `super ` is implemented as part of the binding process for
1810
1830
explicit dotted attribute lookups such as ``super().__getitem__(name) ``.
1811
- It does so by implementing its own :meth: `__getattribute__ ` method for searching
1831
+ It does so by implementing its own :meth: `~object.__getattribute__ ` method
1832
+ for searching
1812
1833
classes in a predictable order that supports cooperative multiple inheritance.
1813
1834
Accordingly, :func: `super ` is undefined for implicit lookups using statements or
1814
1835
operators such as ``super()[name] ``.
0 commit comments