@@ -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,
@@ -663,7 +667,7 @@ are always available. They are listed here in alphabetical order.
663
667
sign: "+" | "-"
664
668
infinity: "Infinity" | "inf"
665
669
nan: "nan"
666
- digitpart: `digit ` (["_"] `digit `)*
670
+ digitpart: `! digit ` (["_"] `! digit `)*
667
671
number: [`digitpart `] "." `digitpart ` | `digitpart ` ["."]
668
672
exponent: ("e" | "E") ["+" | "-"] `digitpart `
669
673
floatnumber: number [`exponent `]
@@ -726,8 +730,8 @@ are always available. They are listed here in alphabetical order.
726
730
727
731
A call to ``format(value, format_spec) `` is translated to
728
732
``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
731
735
:mod: `object ` and the *format_spec * is non-empty, or if either the
732
736
*format_spec * or the return value are not strings.
733
737
@@ -791,9 +795,9 @@ are always available. They are listed here in alphabetical order.
791
795
792
796
.. note ::
793
797
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 `
795
800
truncates the return value based on the bit width of the host machine.
796
- See :meth: `__hash__ <object.__hash__> ` for details.
797
801
798
802
.. function :: help()
799
803
help(request)
@@ -981,7 +985,8 @@ are always available. They are listed here in alphabetical order.
981
985
Return an :term: `iterator ` object. The first argument is interpreted very
982
986
differently depending on the presence of the second argument. Without a
983
987
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
985
990
the sequence protocol (the :meth: `~object.__getitem__ ` method with integer arguments
986
991
starting at ``0 ``). If it does not support either of those protocols,
987
992
: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.
1499
1504
"""Get the current voltage."""
1500
1505
return self._voltage
1501
1506
1502
- The ``@property `` decorator turns the :meth: `voltage ` method into a "getter"
1507
+ The ``@property `` decorator turns the :meth: `! voltage ` method into a "getter"
1503
1508
for a read-only attribute with the same name, and it sets the docstring for
1504
1509
*voltage * to "Get the current voltage."
1505
1510
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
1510
1514
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:
1514
1519
1515
- @property
1516
- def x(self):
1517
- """I'm the 'x' property."""
1518
- return self._x
1520
+ .. testcode ::
1519
1521
1520
- @x.setter
1521
- def x (self, value ):
1522
- self._x = value
1522
+ class C:
1523
+ def __init__ (self):
1524
+ self._x = None
1523
1525
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
1527
1530
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
1531
1534
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.
1534
1545
1535
1546
.. versionchanged :: 3.5
1536
1547
The docstrings of property objects are now writeable.
@@ -1553,17 +1564,18 @@ are always available. They are listed here in alphabetical order.
1553
1564
representation is a string enclosed in angle brackets that contains the name
1554
1565
of the type of the object together with additional information often
1555
1566
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.
1557
1569
If :func: `sys.displayhook ` is not accessible, this function will raise
1558
1570
:exc: `RuntimeError `.
1559
1571
1560
1572
1561
1573
.. function :: reversed(seq)
1562
1574
1563
1575
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 ``).
1567
1579
1568
1580
1569
1581
.. function :: round(number, ndigits=None)
@@ -1634,13 +1646,21 @@ are always available. They are listed here in alphabetical order.
1634
1646
1635
1647
Return a :term: `slice ` object representing the set of indices specified by
1636
1648
``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
+
1641
1660
Slice objects are also generated when extended indexing syntax is used. For
1642
1661
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 `.
1644
1664
1645
1665
1646
1666
.. function :: sorted(iterable, /, *, key=None, reverse=False)
@@ -1800,7 +1820,8 @@ are always available. They are listed here in alphabetical order.
1800
1820
1801
1821
Note that :func: `super ` is implemented as part of the binding process for
1802
1822
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
1804
1825
classes in a predictable order that supports cooperative multiple inheritance.
1805
1826
Accordingly, :func: `super ` is undefined for implicit lookups using statements or
1806
1827
operators such as ``super()[name] ``.
0 commit comments