@@ -2299,28 +2299,17 @@ left undefined.
2299
2299
.. method :: object.__complex__(self)
2300
2300
object.__int__(self)
2301
2301
object.__float__(self)
2302
- object.__round__(self, [,n])
2303
2302
2304
2303
.. index ::
2305
2304
builtin: complex
2306
2305
builtin: int
2307
2306
builtin: float
2308
- builtin: round
2309
2307
2310
2308
Called to implement the built-in functions :func: `complex `,
2311
- :func: `int `, :func: ` float ` and :func: `round `. Should return a value
2309
+ :func: `int ` and :func: `float `. Should return a value
2312
2310
of the appropriate type.
2313
2311
2314
2312
2315
- .. method :: object.__trunc__(self)
2316
-
2317
- Called to implement :meth: `math.trunc `. Should return the value of the
2318
- object truncated to a :class: `numbers.Integral ` (typically an
2319
- :class: `int `). If a class defines :meth: `__trunc__ ` but not
2320
- :meth: `__int__ `, then :meth: `__trunc__ ` is called to implement the
2321
- built-in function :func: `int `.
2322
-
2323
-
2324
2313
.. method :: object.__index__(self)
2325
2314
2326
2315
Called to implement :func: `operator.index `, and whenever Python needs to
@@ -2336,6 +2325,23 @@ left undefined.
2336
2325
the same value.
2337
2326
2338
2327
2328
+ .. method :: object.__round__(self, [,ndigits])
2329
+ object.__trunc__(self)
2330
+ object.__floor__(self)
2331
+ object.__ceil__(self)
2332
+
2333
+ .. index :: builtin: round
2334
+
2335
+ Called to implement the built-in function :func: `round ` and :mod: `math `
2336
+ functions :func: `~math.trunc `, :func: `~math.floor ` and :func: `~math.ceil `.
2337
+ Unless *ndigits * is passed to :meth: `!__round__ ` all these methods should
2338
+ return the value of the object truncated to an :class: `~numbers.Integral `
2339
+ (typically an :class: `int `).
2340
+
2341
+ If :meth: `__int__ ` is not defined then the built-in function :func: `int `
2342
+ falls back to :meth: `__trunc__ `.
2343
+
2344
+
2339
2345
.. _context-managers :
2340
2346
2341
2347
With Statement Context Managers
0 commit comments