mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-26701: Add documentation for __trunc__ (GH-6022)
`int` fails back to `__trunc__` is `__int__` isn't defined, so cover that in the docs.
This commit is contained in:
parent
10485ebd40
commit
308eab979d
3 changed files with 15 additions and 3 deletions
|
@ -731,8 +731,11 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
Return an integer object constructed from a number or string *x*, or return
|
Return an integer object constructed from a number or string *x*, or return
|
||||||
``0`` if no arguments are given. If *x* is a number, return
|
``0`` if no arguments are given. If *x* is a number, return
|
||||||
:meth:`x.__int__() <object.__int__>`. For floating point numbers, this
|
:meth:`x.__int__() <object.__int__>`. If *x* defines
|
||||||
truncates towards zero.
|
:meth:`x.__trunc__() <object.__trunc__>` but not
|
||||||
|
:meth:`x.__int__() <object.__int__>`, then return
|
||||||
|
if :meth:`x.__trunc__() <object.__trunc__>`. For floating point numbers,
|
||||||
|
this truncates towards zero.
|
||||||
|
|
||||||
If *x* is not a number or if *base* is given, then *x* must be a string,
|
If *x* is not a number or if *base* is given, then *x* must be a string,
|
||||||
:class:`bytes`, or :class:`bytearray` instance representing an :ref:`integer
|
:class:`bytes`, or :class:`bytearray` instance representing an :ref:`integer
|
||||||
|
|
|
@ -203,7 +203,7 @@ Number-theoretic and representation functions
|
||||||
|
|
||||||
Return the :class:`~numbers.Real` value *x* truncated to an
|
Return the :class:`~numbers.Real` value *x* truncated to an
|
||||||
:class:`~numbers.Integral` (usually an integer). Delegates to
|
:class:`~numbers.Integral` (usually an integer). Delegates to
|
||||||
``x.__trunc__()``.
|
:meth:`x.__trunc__() <object.__trunc__>`.
|
||||||
|
|
||||||
|
|
||||||
Note that :func:`frexp` and :func:`modf` have a different call/return pattern
|
Note that :func:`frexp` and :func:`modf` have a different call/return pattern
|
||||||
|
|
|
@ -2377,6 +2377,15 @@ left undefined.
|
||||||
of the appropriate type.
|
of the appropriate type.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: object.__trunc__(self)
|
||||||
|
|
||||||
|
Called to implement :meth:`math.trunc`. Should return the value of the
|
||||||
|
object truncated to a :class:`numbers.Integral` (typically an
|
||||||
|
:class:`int`). If a class defines :meth:`__trunc__` but not
|
||||||
|
:meth:`__int__`, then :meth:`__trunc__` is called to implement the
|
||||||
|
built-in function :func:`int`.
|
||||||
|
|
||||||
|
|
||||||
.. method:: object.__index__(self)
|
.. method:: object.__index__(self)
|
||||||
|
|
||||||
Called to implement :func:`operator.index`, and whenever Python needs to
|
Called to implement :func:`operator.index`, and whenever Python needs to
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue