summaryrefslogtreecommitdiffstats
path: root/Doc/reference
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-03-10 15:10:45 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2018-03-10 15:10:45 (GMT)
commit1028ca4f04c14cf40a8f3e7951623a96ec0143c2 (patch)
tree8231cce71807da12d61a752828ea229053fa7129 /Doc/reference
parent19b42fe97cc15ff123f7ccb61a26fed817e850f7 (diff)
downloadcpython-1028ca4f04c14cf40a8f3e7951623a96ec0143c2.zip
cpython-1028ca4f04c14cf40a8f3e7951623a96ec0143c2.tar.gz
cpython-1028ca4f04c14cf40a8f3e7951623a96ec0143c2.tar.bz2
bpo-26701: Add documentation for __trunc__ (GH-6050)
`int` fails back to `__trunc__` is `__int__` isn't defined, so cover that in the docs. (cherry picked from commit 308eab979d153f1ab934383dc08bc4546ced8b6c) Co-authored-by: Eric Appelt <eric.appelt@gmail.com>
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/datamodel.rst9
1 files changed, 9 insertions, 0 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index c95f4a9..90f3a2a 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -2312,6 +2312,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