mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
bpo-26701: Add documentation for __trunc__ (GH-6049)
`int` fails back to `__trunc__` is `__int__` isn't defined, so cover
that in the docs.
(cherry picked from commit 308eab979d)
Co-authored-by: Eric Appelt <eric.appelt@gmail.com>
This commit is contained in:
parent
6826589415
commit
f34e0d60e2
3 changed files with 15 additions and 3 deletions
|
|
@ -2377,6 +2377,15 @@ left undefined.
|
|||
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)
|
||||
|
||||
Called to implement :func:`operator.index`, and whenever Python needs to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue