bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)

This commit is contained in:
Serhiy Storchaka 2019-06-02 00:05:48 +03:00 committed by GitHub
parent 1a4d9ffa1a
commit bdbad71b9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 181 additions and 23 deletions

View file

@ -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])