From c02d01e3d2a177785db5320b930f99c096ebdebc Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 18:01:33 +0100 Subject: [PATCH 01/17] Remove deprecated delegation of int to __trunc__ --- Doc/library/functions.rst | 10 ++-- Doc/reference/datamodel.rst | 7 +-- Lib/test/test_int.py | 96 +------------------------------------ Lib/test/test_long.py | 9 ---- Objects/abstract.c | 32 +------------ 5 files changed, 10 insertions(+), 144 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index cb9b650badcfbd..94652af570cd67 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -932,8 +932,7 @@ are always available. They are listed here in alphabetical order. Return an integer object constructed from a number or string *x*, or return ``0`` if no arguments are given. If *x* defines :meth:`~object.__int__`, ``int(x)`` returns ``x.__int__()``. If *x* defines :meth:`~object.__index__`, - it returns ``x.__index__()``. If *x* defines :meth:`~object.__trunc__`, - it returns ``x.__trunc__()``. + it returns ``x.__index__()``. For floating point numbers, this truncates towards zero. If *x* is not a number or if *base* is given, then *x* must be a string, @@ -971,9 +970,6 @@ are always available. They are listed here in alphabetical order. .. versionchanged:: 3.8 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 @@ -982,6 +978,10 @@ are always available. They are listed here in alphabetical order. See the :ref:`integer string conversion length limitation ` documentation. + .. deprecated-removed:: 3.11 3.14 + :class:`int` will no longer delegate 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 0fe9681f93f135..74e69d64885eaf 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. + .. deprecated-removed:: 3.11 3.14 + :class:`int` will no longer delegate to the :meth:`~object.__trunc__` method. .. _context-managers: diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index caeccbe1fed026..ce9febd741bba2 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -402,68 +402,8 @@ def __trunc__(self): class JustTrunc(base): def __trunc__(self): return 42 - with self.assertWarns(DeprecationWarning): - self.assertEqual(int(JustTrunc()), 42) - - class ExceptionalTrunc(base): - def __trunc__(self): - 1 / 0 - with self.assertRaises(ZeroDivisionError), \ - self.assertWarns(DeprecationWarning): - int(ExceptionalTrunc()) - - for trunc_result_base in (object, Classic): - class Index(trunc_result_base): - def __index__(self): - return 42 - - class TruncReturnsNonInt(base): - def __trunc__(self): - return Index() - with self.assertWarns(DeprecationWarning): - self.assertEqual(int(TruncReturnsNonInt()), 42) - - class Intable(trunc_result_base): - def __int__(self): - return 42 - - class TruncReturnsNonIndex(base): - def __trunc__(self): - return Intable() - with self.assertWarns(DeprecationWarning): - self.assertEqual(int(TruncReturnsNonInt()), 42) - - class NonIntegral(trunc_result_base): - def __trunc__(self): - # Check that we avoid infinite recursion. - return NonIntegral() - - class TruncReturnsNonIntegral(base): - def __trunc__(self): - return NonIntegral() - try: - with self.assertWarns(DeprecationWarning): - int(TruncReturnsNonIntegral()) - except TypeError as e: - self.assertEqual(str(e), - "__trunc__ returned non-Integral" - " (type NonIntegral)") - else: - self.fail("Failed to raise TypeError with %s" % - ((base, trunc_result_base),)) - - # Regression test for bugs.python.org/issue16060. - class BadInt(trunc_result_base): - def __int__(self): - return 42.0 - - class TruncReturnsBadInt(base): - def __trunc__(self): - return BadInt() - - with self.assertRaises(TypeError), \ - self.assertWarns(DeprecationWarning): - int(TruncReturnsBadInt()) + with self.assertRaises(TypeError): + int(JustTrunc()) def test_int_subclass_with_index(self): class MyIndex(int): @@ -514,18 +454,6 @@ class BadInt2(int): def __int__(self): return True - class TruncReturnsBadIndex: - def __trunc__(self): - return BadIndex() - - class TruncReturnsBadInt: - def __trunc__(self): - return BadInt() - - class TruncReturnsIntSubclass: - def __trunc__(self): - return True - bad_int = BadIndex() with self.assertWarns(DeprecationWarning): n = int(bad_int) @@ -549,26 +477,6 @@ def __trunc__(self): self.assertEqual(n, 1) self.assertIs(type(n), int) - bad_int = TruncReturnsBadIndex() - with self.assertWarns(DeprecationWarning): - n = int(bad_int) - self.assertEqual(n, 1) - self.assertIs(type(n), int) - - bad_int = TruncReturnsBadInt() - with self.assertWarns(DeprecationWarning): - self.assertRaises(TypeError, int, bad_int) - - good_int = TruncReturnsIntSubclass() - with self.assertWarns(DeprecationWarning): - n = int(good_int) - self.assertEqual(n, 1) - self.assertIs(type(n), int) - with self.assertWarns(DeprecationWarning): - n = IntSubclass(good_int) - self.assertEqual(n, 1) - self.assertIs(type(n), IntSubclass) - def test_error_message(self): def check(s, base=None): with self.assertRaises(ValueError, diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 41b973da2c7df0..3b2e7c4e71d10d 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -386,15 +386,6 @@ def __long__(self): return 42 self.assertRaises(TypeError, int, JustLong()) - class LongTrunc: - # __long__ should be ignored in 3.x - def __long__(self): - return 42 - def __trunc__(self): - return 1729 - with self.assertWarns(DeprecationWarning): - self.assertEqual(int(LongTrunc()), 1729) - def check_float_conversion(self, n): # Check that int -> float conversion behaviour matches # that of the pure Python version above. diff --git a/Objects/abstract.c b/Objects/abstract.c index 8357175aa5591e..68bc10a44bb16b 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1560,40 +1560,10 @@ PyNumber_Long(PyObject *o) Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); return result; } + if (m && m->nb_index) { return PyNumber_Index(o); } - trunc_func = _PyObject_LookupSpecial(o, &_Py_ID(__trunc__)); - if (trunc_func) { - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "The delegation of int() to __trunc__ is deprecated.", 1)) { - Py_DECREF(trunc_func); - return NULL; - } - result = _PyObject_CallNoArgs(trunc_func); - Py_DECREF(trunc_func); - if (result == NULL || PyLong_CheckExact(result)) { - return result; - } - if (PyLong_Check(result)) { - Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); - return result; - } - /* __trunc__ is specified to return an Integral type, - but int() needs to return an int. */ - if (!PyIndex_Check(result)) { - PyErr_Format( - PyExc_TypeError, - "__trunc__ returned non-Integral (type %.200s)", - Py_TYPE(result)->tp_name); - Py_DECREF(result); - return NULL; - } - Py_SETREF(result, PyNumber_Index(result)); - return result; - } - if (PyErr_Occurred()) - return NULL; if (PyUnicode_Check(o)) /* The below check is done in PyLong_FromUnicodeObject(). */ From 07e24bbe85e11374a3fef6593fecd1a2700fb8de Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 18:53:53 +0100 Subject: [PATCH 02/17] Add news entry --- .../2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst new file mode 100644 index 00000000000000..fd5ec9e792f6c8 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst @@ -0,0 +1,2 @@ +Remove the previously-deprecated delegation of :class:`int` to +:meth:`~object.__trunc__`. From c78d6375ac84d348f950c20f975ac6253e32912c Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 18:59:23 +0100 Subject: [PATCH 03/17] Add what's new entry --- Doc/whatsnew/3.14.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index bc7fe64e68bb18..c385c728981591 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -207,6 +207,11 @@ Others It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed by Jelle Zijlstra in :gh:`118767`.) +* The :class:`int` built-in will no longer delegate to + :meth:`~object.__trunc__`. Classes that want to support conversion to `int` + must implement either :meth:`~object.__int__` or :meth:`~object.__index__`. + (Contributed by Mark Dickinson in :gh:`119742`). + Porting to Python 3.14 ====================== From 0088603860efe9d906a233b935dd15b07e2f5f2f Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 19:01:42 +0100 Subject: [PATCH 04/17] Fix PR number --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index c385c728981591..90793b9df2410d 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -210,7 +210,7 @@ Others * The :class:`int` built-in will no longer delegate to :meth:`~object.__trunc__`. Classes that want to support conversion to `int` must implement either :meth:`~object.__int__` or :meth:`~object.__index__`. - (Contributed by Mark Dickinson in :gh:`119742`). + (Contributed by Mark Dickinson in :gh:`119743`). Porting to Python 3.14 From ca6af89c26091bb2823d86e85a5345315e0f2eda Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 19:05:09 +0100 Subject: [PATCH 05/17] Fix reST markup --- Doc/whatsnew/3.14.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 90793b9df2410d..6add6a64cf4631 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -208,9 +208,9 @@ Others by Jelle Zijlstra in :gh:`118767`.) * The :class:`int` built-in will no longer delegate to - :meth:`~object.__trunc__`. Classes that want to support conversion to `int` - must implement either :meth:`~object.__int__` or :meth:`~object.__index__`. - (Contributed by Mark Dickinson in :gh:`119743`). + :meth:`~object.__trunc__`. Classes that want to support conversion to + :class:`int` must implement either :meth:`~object.__int__` or + :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`). Porting to Python 3.14 From 834d087eda48849de97209c75f7cb59a50cd59dd Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 19:15:59 +0100 Subject: [PATCH 06/17] Regenerate includes --- Include/internal/pycore_global_objects_fini_generated.h | 1 - Include/internal/pycore_global_strings.h | 1 - Include/internal/pycore_runtime_init_generated.h | 1 - Include/internal/pycore_unicodeobject_generated.h | 3 --- 4 files changed, 6 deletions(-) diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h index a0f8fb71c1ff37..b9fae11dfaa85c 100644 --- a/Include/internal/pycore_global_objects_fini_generated.h +++ b/Include/internal/pycore_global_objects_fini_generated.h @@ -732,7 +732,6 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) { _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__subclasscheck__)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__subclasshook__)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__truediv__)); - _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__trunc__)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__type_params__)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__typing_is_unpacked_typevartuple__)); _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(__typing_prepare_subst__)); diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 57d85020f14e05..aa66b20859a472 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -221,7 +221,6 @@ struct _Py_global_strings { STRUCT_FOR_ID(__subclasscheck__) STRUCT_FOR_ID(__subclasshook__) STRUCT_FOR_ID(__truediv__) - STRUCT_FOR_ID(__trunc__) STRUCT_FOR_ID(__type_params__) STRUCT_FOR_ID(__typing_is_unpacked_typevartuple__) STRUCT_FOR_ID(__typing_prepare_subst__) diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h index e62ebd659d30e8..b27720e9ff6ecf 100644 --- a/Include/internal/pycore_runtime_init_generated.h +++ b/Include/internal/pycore_runtime_init_generated.h @@ -730,7 +730,6 @@ extern "C" { INIT_ID(__subclasscheck__), \ INIT_ID(__subclasshook__), \ INIT_ID(__truediv__), \ - INIT_ID(__trunc__), \ INIT_ID(__type_params__), \ INIT_ID(__typing_is_unpacked_typevartuple__), \ INIT_ID(__typing_prepare_subst__), \ diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h index 892f580e8a6846..c61c556b758769 100644 --- a/Include/internal/pycore_unicodeobject_generated.h +++ b/Include/internal/pycore_unicodeobject_generated.h @@ -504,9 +504,6 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) { string = &_Py_ID(__truediv__); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); - string = &_Py_ID(__trunc__); - assert(_PyUnicode_CheckConsistency(string, 1)); - _PyUnicode_InternInPlace(interp, &string); string = &_Py_ID(__type_params__); assert(_PyUnicode_CheckConsistency(string, 1)); _PyUnicode_InternInPlace(interp, &string); From 39e164d3432ec5d8f0825b7236049a046e78d3ae Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 19:36:35 +0100 Subject: [PATCH 07/17] Remove unused variable --- Objects/abstract.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Objects/abstract.c b/Objects/abstract.c index 68bc10a44bb16b..c5c2cc1e8a226a 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1521,7 +1521,6 @@ PyNumber_Long(PyObject *o) { PyObject *result; PyNumberMethods *m; - PyObject *trunc_func; Py_buffer view; if (o == NULL) { From c6a8f626ae5e99e2d91d9cd105fd978557f9c634 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 21:21:23 +0100 Subject: [PATCH 08/17] Use 'versionchanged', not 'deprecated-removed' --- Doc/library/functions.rst | 2 +- Doc/reference/datamodel.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 94652af570cd67..cd13c4ea3ef5de 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -978,7 +978,7 @@ are always available. They are listed here in alphabetical order. See the :ref:`integer string conversion length limitation ` documentation. - .. deprecated-removed:: 3.11 3.14 + .. versionchanged:: 3.14 :class:`int` will no longer delegate to the :meth:`~object.__trunc__` method. diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 74e69d64885eaf..c641ee77d7fb7e 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -3127,7 +3127,7 @@ left undefined. return the value of the object truncated to an :class:`~numbers.Integral` (typically an :class:`int`). - .. deprecated-removed:: 3.11 3.14 + .. versionchanged:: 3.14 :class:`int` will no longer delegate to the :meth:`~object.__trunc__` method. From 7492da8cb64922147227858e9ef5cd120632a8ba Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 21:22:36 +0100 Subject: [PATCH 09/17] Change :class: to :func: in docs --- Doc/library/functions.rst | 2 +- Doc/reference/datamodel.rst | 2 +- Doc/whatsnew/3.14.rst | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index cd13c4ea3ef5de..1b18bd15ef5693 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -979,7 +979,7 @@ are always available. They are listed here in alphabetical order. ` documentation. .. versionchanged:: 3.14 - :class:`int` will no longer delegate to the :meth:`~object.__trunc__` method. + :func:`int` will no longer delegate to the :meth:`~object.__trunc__` method. .. function:: isinstance(object, classinfo) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index c641ee77d7fb7e..1035b9ae12848f 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -3128,7 +3128,7 @@ left undefined. (typically an :class:`int`). .. versionchanged:: 3.14 - :class:`int` will no longer delegate to the :meth:`~object.__trunc__` method. + :func:`int` will no longer delegate to the :meth:`~object.__trunc__` method. .. _context-managers: diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 6add6a64cf4631..3f8eabedc50f4f 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -207,7 +207,7 @@ Others It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed by Jelle Zijlstra in :gh:`118767`.) -* The :class:`int` built-in will no longer delegate to +* The :func:`int` built-in will no longer delegate to :meth:`~object.__trunc__`. Classes that want to support conversion to :class:`int` must implement either :meth:`~object.__int__` or :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`). @@ -244,4 +244,3 @@ Deprecated Removed ------- - From cd34a34c95fc13b76c3cd413370f65fd1ac76931 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 21:24:15 +0100 Subject: [PATCH 10/17] Fix one missed :class: to :func: change --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 3f8eabedc50f4f..8b7c7e3536be68 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -209,7 +209,7 @@ Others * The :func:`int` built-in will no longer delegate to :meth:`~object.__trunc__`. Classes that want to support conversion to - :class:`int` must implement either :meth:`~object.__int__` or + :func:`int` must implement either :meth:`~object.__int__` or :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`). From 34899dd842a0f53be6eb23b3966edd968f7a1485 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 21:25:04 +0100 Subject: [PATCH 11/17] And one more missed :class: to :func: change --- .../2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst b/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst index fd5ec9e792f6c8..111e096d262ea0 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-05-29-18-53-43.gh-issue-119740.zP2JNM.rst @@ -1,2 +1,2 @@ -Remove the previously-deprecated delegation of :class:`int` to +Remove the previously-deprecated delegation of :func:`int` to :meth:`~object.__trunc__`. From 8ff4651eb8e4e02b9e12ad8c3c466c6fe63e5df6 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Wed, 29 May 2024 21:32:39 +0100 Subject: [PATCH 12/17] Revert unrelated spacing changes --- Doc/library/functions.rst | 1 - Doc/whatsnew/3.14.rst | 1 + Objects/abstract.c | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index 1b18bd15ef5693..a2f7a4bc5dc840 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -981,7 +981,6 @@ are always available. They are listed here in alphabetical order. .. versionchanged:: 3.14 :func:`int` will no longer delegate 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/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 8b7c7e3536be68..262ebfdc95b4e4 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -244,3 +244,4 @@ Deprecated Removed ------- + diff --git a/Objects/abstract.c b/Objects/abstract.c index c5c2cc1e8a226a..200817064e3cda 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1559,7 +1559,6 @@ PyNumber_Long(PyObject *o) Py_SETREF(result, _PyLong_Copy((PyLongObject *)result)); return result; } - if (m && m->nb_index) { return PyNumber_Index(o); } From 1c2a638fc5b76a6f3223eec6609ee44d138bf800 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 2 Jun 2024 09:34:05 +0100 Subject: [PATCH 13/17] More direct wording MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/library/functions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index a2f7a4bc5dc840..950139e9eb1419 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -979,7 +979,7 @@ are always available. They are listed here in alphabetical order. ` documentation. .. versionchanged:: 3.14 - :func:`int` will no longer delegate to the :meth:`~object.__trunc__` method. + :func:`int` no longer delegates to the :meth:`~object.__trunc__` method. .. function:: isinstance(object, classinfo) From 26d5833a7419fbc359034fec535020c8d1a5ab0f Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 2 Jun 2024 09:35:04 +0100 Subject: [PATCH 14/17] Grammar nit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 262ebfdc95b4e4..4c1fc0068e2088 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -210,7 +210,7 @@ Others * The :func:`int` built-in will no longer delegate to :meth:`~object.__trunc__`. Classes that want to support conversion to :func:`int` must implement either :meth:`~object.__int__` or - :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`). + :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`.) Porting to Python 3.14 From 03308ef6c615221d9c14fc23418c72ea6d1157b2 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 2 Jun 2024 09:37:08 +0100 Subject: [PATCH 15/17] Fix reference to function when we really want a reference to a type Co-authored-by: Serhiy Storchaka --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 4c1fc0068e2088..2cd9a36fca3710 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -209,7 +209,7 @@ Others * The :func:`int` built-in will no longer delegate to :meth:`~object.__trunc__`. Classes that want to support conversion to - :func:`int` must implement either :meth:`~object.__int__` or + integer must implement either :meth:`~object.__int__` or :meth:`~object.__index__`. (Contributed by Mark Dickinson in :gh:`119743`.) From 506b821784a1deacc1d2e1d25fcb824d65973ad8 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 2 Jun 2024 09:37:22 +0100 Subject: [PATCH 16/17] Cleaner wording. --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 2cd9a36fca3710..d9f664f47cb7ae 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -207,7 +207,7 @@ Others It had previously raised a :exc:`DeprecationWarning` since Python 3.9. (Contributed by Jelle Zijlstra in :gh:`118767`.) -* The :func:`int` built-in will no longer delegate to +* 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`.) From af6793a2b02b97c52f5dbbcd68cfb845dc19e6ce Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Sun, 2 Jun 2024 09:40:04 +0100 Subject: [PATCH 17/17] Reword one more instance of 'will no longer delegate' --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 1035b9ae12848f..62f23e75043533 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -3128,7 +3128,7 @@ left undefined. (typically an :class:`int`). .. versionchanged:: 3.14 - :func:`int` will no longer delegate to the :meth:`~object.__trunc__` method. + :func:`int` no longer delegates to the :meth:`~object.__trunc__` method. .. _context-managers: