Skip to content

Commit 496431f

Browse files
bpo-26701: Improve documentation for the rounding special methods. (#6054)
1 parent 308eab9 commit 496431f

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

Doc/reference/datamodel.rst

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,28 +2364,17 @@ left undefined.
23642364
.. method:: object.__complex__(self)
23652365
object.__int__(self)
23662366
object.__float__(self)
2367-
object.__round__(self, [,n])
23682367

23692368
.. index::
23702369
builtin: complex
23712370
builtin: int
23722371
builtin: float
2373-
builtin: round
23742372

23752373
Called to implement the built-in functions :func:`complex`,
2376-
:func:`int`, :func:`float` and :func:`round`. Should return a value
2374+
:func:`int` and :func:`float`. Should return a value
23772375
of the appropriate type.
23782376

23792377

2380-
.. method:: object.__trunc__(self)
2381-
2382-
Called to implement :meth:`math.trunc`. Should return the value of the
2383-
object truncated to a :class:`numbers.Integral` (typically an
2384-
:class:`int`). If a class defines :meth:`__trunc__` but not
2385-
:meth:`__int__`, then :meth:`__trunc__` is called to implement the
2386-
built-in function :func:`int`.
2387-
2388-
23892378
.. method:: object.__index__(self)
23902379

23912380
Called to implement :func:`operator.index`, and whenever Python needs to
@@ -2401,6 +2390,23 @@ left undefined.
24012390
the same value.
24022391

24032392

2393+
.. method:: object.__round__(self, [,ndigits])
2394+
object.__trunc__(self)
2395+
object.__floor__(self)
2396+
object.__ceil__(self)
2397+
2398+
.. index:: builtin: round
2399+
2400+
Called to implement the built-in function :func:`round` and :mod:`math`
2401+
functions :func:`~math.trunc`, :func:`~math.floor` and :func:`~math.ceil`.
2402+
Unless *ndigits* is passed to :meth:`!__round__` all these methods should
2403+
return the value of the object truncated to an :class:`~numbers.Integral`
2404+
(typically an :class:`int`).
2405+
2406+
If :meth:`__int__` is not defined then the built-in function :func:`int`
2407+
falls back to :meth:`__trunc__`.
2408+
2409+
24042410
.. _context-managers:
24052411

24062412
With Statement Context Managers

0 commit comments

Comments
 (0)