diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-02-25 15:57:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-25 15:57:58 (GMT) |
commit | 6a44f6eef3d0958d88882347190b3e2d1222c2e9 (patch) | |
tree | bb6474b1e094a672837c3333a081fa4d5d7638f2 /Doc/whatsnew | |
parent | d90a141bb947b68601f8d1f37bc98f7b524f0e01 (diff) | |
download | cpython-6a44f6eef3d0958d88882347190b3e2d1222c2e9.zip cpython-6a44f6eef3d0958d88882347190b3e2d1222c2e9.tar.gz cpython-6a44f6eef3d0958d88882347190b3e2d1222c2e9.tar.bz2 |
bpo-36048: Use __index__() instead of __int__() for implicit conversion if available. (GH-11952)
Deprecate using the __int__() method in implicit conversions of Python
numbers to C integers.
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r-- | Doc/whatsnew/3.8.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.8.rst b/Doc/whatsnew/3.8.rst index 68a4457..154fd66 100644 --- a/Doc/whatsnew/3.8.rst +++ b/Doc/whatsnew/3.8.rst @@ -458,6 +458,17 @@ Build and C API Changes (Contributed by Antoine Pitrou in :issue:`32430`.) +* Functions that convert Python number to C integer like + :c:func:`PyLong_AsLong` and argument parsing functions like + :c:func:`PyArg_ParseTuple` with integer converting format units like ``'i'`` + will now use the :meth:`~object.__index__` special method instead of + :meth:`~object.__int__`, if available. The deprecation warning will be + emitted for objects with the ``__int__()`` method but without the + ``__index__()`` method (like :class:`~decimal.Decimal` and + :class:`~fractions.Fraction`). :c:func:`PyNumber_Check` will now return + ``1`` for objects implementing ``__index__()``. + (Contributed by Serhiy Storchaka in :issue:`36048`.) + Deprecated ========== @@ -508,6 +519,15 @@ Deprecated * The :meth:`~threading.Thread.isAlive()` method of :class:`threading.Thread` has been deprecated. (Contributed by Dong-hee Na in :issue:`35283`.) +* Many builtin and extension functions that take integer arguments will + now emit a deprecation warning for :class:`~decimal.Decimal`\ s, + :class:`~fractions.Fraction`\ s and any other objects that can be converted + to integers only with a loss (e.g. that have the :meth:`~object.__int__` + method but do not have the :meth:`~object.__index__` method). In future + version they will be errors. + (Contributed by Serhiy Storchaka in :issue:`36048`.) + + API and Feature Removals ======================== |