mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
This commit is contained in:
parent
1a4d9ffa1a
commit
bdbad71b9d
15 changed files with 181 additions and 23 deletions
|
|
@ -2394,11 +2394,9 @@ left undefined.
|
|||
functions). Presence of this method indicates that the numeric object is
|
||||
an integer type. Must return an integer.
|
||||
|
||||
.. note::
|
||||
|
||||
In order to have a coherent integer type class, when :meth:`__index__` is
|
||||
defined :meth:`__int__` should also be defined, and both should return
|
||||
the same value.
|
||||
If :meth:`__int__`, :meth:`__float__` and :meth:`__complex__` are not
|
||||
defined then corresponding built-in functions :func:`int`, :func:`float`
|
||||
and :func:`complex` fall back to :meth:`__index__`.
|
||||
|
||||
|
||||
.. method:: object.__round__(self, [,ndigits])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue