diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2024-06-02 09:16:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-02 09:16:49 (GMT) |
commit | f79ffc879b919604ed5de22ece83825006cf9a17 (patch) | |
tree | 4174214b7ad81d2277e584d4fa9e6c1ccec3e95a /Doc | |
parent | 4aed319a8eb63b205d6007c36713cacdbf1ce8a3 (diff) | |
download | cpython-f79ffc879b919604ed5de22ece83825006cf9a17.zip cpython-f79ffc879b919604ed5de22ece83825006cf9a17.tar.gz cpython-f79ffc879b919604ed5de22ece83825006cf9a17.tar.bz2 |
gh-119740: Remove deprecated trunc delegation (#119743)
Remove the delegation of `int` to the `__trunc__` special method: `int` will now only delegate to `__int__` and `__index__` (in that order). `__trunc__` continues to exist, but its sole purpose is to support `math.trunc`.
---------
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/functions.rst | 11 | ||||
-rw-r--r-- | Doc/reference/datamodel.rst | 7 | ||||
-rw-r--r-- | Doc/whatsnew/3.14.rst | 5 |
3 files changed, 12 insertions, 11 deletions
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 7291461..4617767 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1004,9 +1004,8 @@ are always available. They are listed here in alphabetical order. 115 If the argument defines :meth:`~object.__int__`, - ``int(x)`` returns ``x.__int__()``. If the argument defines :meth:`~object.__index__`, - it returns ``x.__index__()``. If the argument defines :meth:`~object.__trunc__`, - it returns ``x.__trunc__()``. + ``int(x)`` returns ``x.__int__()``. If the argument defines + :meth:`~object.__index__`, it returns ``x.__index__()``. For floating point numbers, this truncates towards zero. If the argument is not a number or if *base* is given, then it must be a string, @@ -1045,9 +1044,6 @@ are always available. They are listed here in alphabetical order. Falls back to :meth:`~object.__index__` if :meth:`~object.__int__` is not defined. .. versionchanged:: 3.11 - The delegation to :meth:`~object.__trunc__` is deprecated. - - .. versionchanged:: 3.11 :class:`int` string inputs and string representations can be limited to help avoid denial of service attacks. A :exc:`ValueError` is raised when the limit is exceeded while converting a string to an :class:`int` or @@ -1055,6 +1051,9 @@ are always available. They are listed here in alphabetical order. See the :ref:`integer string conversion length limitation <int_max_str_digits>` documentation. + .. versionchanged:: 3.14 + :func:`int` no longer delegates to the :meth:`~object.__trunc__` method. + .. function:: isinstance(object, classinfo) Return ``True`` if the *object* argument is an instance of the *classinfo* diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 9110060..af4c585 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -3127,11 +3127,8 @@ left undefined. return the value of the object truncated to an :class:`~numbers.Integral` (typically an :class:`int`). - The built-in function :func:`int` falls back to :meth:`__trunc__` if neither - :meth:`__int__` nor :meth:`__index__` is defined. - - .. versionchanged:: 3.11 - The delegation of :func:`int` to :meth:`__trunc__` is deprecated. + .. versionchanged:: 3.14 + :func:`int` no longer delegates to the :meth:`~object.__trunc__` method. .. _context-managers: diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 45ffb28..9f471d2 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -225,6 +225,11 @@ Others It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed by Jelle Zijlstra in :gh:`118767`.) +* The :func:`int` built-in no longer delegates to + :meth:`~object.__trunc__`. Classes that want to support conversion to + integer must implement either :meth:`~object.__int__` or + :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`.) + Porting to Python 3.14 ====================== |