diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-06-01 21:05:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 21:05:48 (GMT) |
commit | bdbad71b9def0b86433de12cecca022eee91bd9f (patch) | |
tree | 147c8a3e08454a95e0e4900388d88f7b65430f63 /Doc/c-api | |
parent | 1a4d9ffa1aecd7e750195f2be06d3d16c7a3a88f (diff) | |
download | cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.zip cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.gz cpython-bdbad71b9def0b86433de12cecca022eee91bd9f.tar.bz2 |
bpo-20092. Use __index__ in constructors of int, float and complex. (GH-13108)
Diffstat (limited to 'Doc/c-api')
-rw-r--r-- | Doc/c-api/complex.rst | 8 | ||||
-rw-r--r-- | Doc/c-api/float.rst | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/Doc/c-api/complex.rst b/Doc/c-api/complex.rst index 675bd01..06dbb25 100644 --- a/Doc/c-api/complex.rst +++ b/Doc/c-api/complex.rst @@ -129,4 +129,10 @@ Complex Numbers as Python Objects If *op* is not a Python complex number object but has a :meth:`__complex__` method, this method will first be called to convert *op* to a Python complex - number object. Upon failure, this method returns ``-1.0`` as a real value. + number object. If ``__complex__()`` is not defined then it falls back to + :meth:`__float__`. If ``__float__()`` is not defined then it falls back + to :meth:`__index__`. Upon failure, this method returns ``-1.0`` as a real + value. + + .. versionchanged:: 3.8 + Use :meth:`__index__` if available. diff --git a/Doc/c-api/float.rst b/Doc/c-api/float.rst index 8a99642..057ff52 100644 --- a/Doc/c-api/float.rst +++ b/Doc/c-api/float.rst @@ -47,9 +47,13 @@ Floating Point Objects Return a C :c:type:`double` representation of the contents of *pyfloat*. If *pyfloat* is not a Python floating point object but has a :meth:`__float__` method, this method will first be called to convert *pyfloat* into a float. + If ``__float__()`` is not defined then it falls back to :meth:`__index__`. This method returns ``-1.0`` upon failure, so one should call :c:func:`PyErr_Occurred` to check for errors. + .. versionchanged:: 3.8 + Use :meth:`__index__` if available. + .. c:function:: double PyFloat_AS_DOUBLE(PyObject *pyfloat) |