From bac8a249bab045c767f4952c21fed7a352bc5f50 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Fri, 7 Feb 2025 13:27:17 +0530 Subject: [PATCH 01/11] gh-129027: Raise DeprecationWarning for sys._clear_type_cache --- Doc/deprecations/pending-removal-in-future.rst | 3 +++ Doc/whatsnew/3.14.rst | 2 ++ Lib/test/test_cmd_line.py | 4 +++- Lib/test/test_sys.py | 4 +++- Lib/test/test_type_cache.py | 10 +++++++++- .../2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst | 2 ++ Python/sysmodule.c | 7 +++++++ 7 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index ea7581bf16bd34..e2aa6ac9b17d42 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -155,3 +155,6 @@ although there is currently no date scheduled for their removal. * :meth:`zipimport.zipimporter.load_module` is deprecated: use :meth:`~zipimport.zipimporter.exec_module` instead. + +* :func:`sys._clear_type_cache` is deprecated. + use :func:`sys._clear_internal_caches` instead. diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a95fc7a4b6a9fa..348a0f45e1cebf 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -661,6 +661,8 @@ sys * On FreeBSD, :data:`sys.platform` doesn't contain the major version anymore. It is always ``'freebsd'``, instead of ``'freebsd13'`` or ``'freebsd14'``. +* Raise :exc:`DeprecationWarning` for :func:`sys._clear_type_cache`. This + function was deprecated in Python 3.13 but it didn't raise a runtime warning. sys.monitoring -------------- diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index b949b310ac0f5f..6489969c8f7f3e 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -11,7 +11,7 @@ import unittest from test import support from test.support import os_helper -from test.support import force_not_colorized +from test.support import force_not_colorized, warnings_helper from test.support import threading_helper from test.support.script_helper import ( spawn_python, kill_python, assert_python_ok, assert_python_failure, @@ -932,12 +932,14 @@ def test_python_asyncio_debug(self): self.assertIn(b'True', out) @unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option") + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_python_dump_refs(self): code = 'import sys; sys._clear_type_cache()' rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1') self.assertEqual(rc, 0) @unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option") + @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_python_dump_refs_file(self): with tempfile.NamedTemporaryFile() as dump_file: code = 'import sys; sys._clear_type_cache()' diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 39857445a02255..1f346d74ad98ac 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -850,7 +850,9 @@ def test_sys_getwindowsversion_no_instantiation(self): @test.support.cpython_only def test_clear_type_cache(self): - sys._clear_type_cache() + with self.assertWarnsRegex(DeprecationWarning, + r"sys._clear_type_cache\(\) is deprecated.*"): + sys._clear_type_cache() @force_not_colorized @support.requires_subprocess() diff --git a/Lib/test/test_type_cache.py b/Lib/test/test_type_cache.py index ee64f89358ed55..cc2131bb3ed4f8 100644 --- a/Lib/test/test_type_cache.py +++ b/Lib/test/test_type_cache.py @@ -2,7 +2,10 @@ import unittest import dis from test import support -from test.support import import_helper, requires_specialization, requires_specialization_ft +from test.support import ( + import_helper, requires_specialization, + requires_specialization_ft, warnings_helper +) try: from sys import _clear_type_cache except ImportError: @@ -15,11 +18,13 @@ type_assign_specific_version_unsafe = _testinternalcapi.type_assign_specific_version_unsafe type_assign_version = _testcapi.type_assign_version type_modified = _testcapi.type_modified +ignore_deprecation = warnings_helper.ignore_warnings(category=DeprecationWarning) @support.cpython_only @unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache") class TypeCacheTests(unittest.TestCase): + @ignore_deprecation def test_tp_version_tag_unique(self): """tp_version_tag should be unique assuming no overflow, even after clearing type cache. @@ -61,6 +66,7 @@ class C: self.assertNotEqual(type_get_version(C), 0) self.assertNotEqual(type_get_version(C), c_ver) + @ignore_deprecation def test_type_assign_specific_version(self): """meta-test for type_assign_specific_version_unsafe""" class C: @@ -111,6 +117,8 @@ class HolderSub(Holder): @support.cpython_only class TypeCacheWithSpecializationTests(unittest.TestCase): + + @ignore_deprecation def tearDown(self): _clear_type_cache() diff --git a/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst b/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst new file mode 100644 index 00000000000000..0d8782e3cd797d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst @@ -0,0 +1,2 @@ +Raise DeprecationWarning for :func:`sys._clear_type_cache`. This function was deprecated in Python 3.13 +but it didn't raise a runtime warning. diff --git a/Python/sysmodule.c b/Python/sysmodule.c index d5cb448eb618e8..966ea698ea5337 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2146,6 +2146,13 @@ static PyObject * sys__clear_type_cache_impl(PyObject *module) /*[clinic end generated code: output=20e48ca54a6f6971 input=127f3e04a8d9b555]*/ { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "sys._clear_type_cache() is deprecated and scheduled" + " for removal in a future version. Use the more general" + " sys._clear_internal_caches() function instead.", + 1) < 0){ + return NULL; + } PyType_ClearCache(); Py_RETURN_NONE; } From 3d2bca743f2731379a9da6d414e88ba3eaa1d817 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Fri, 7 Feb 2025 16:40:51 +0530 Subject: [PATCH 02/11] Update Doc/whatsnew/3.14.rst 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 348a0f45e1cebf..f092e070003bb6 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -664,6 +664,7 @@ sys * Raise :exc:`DeprecationWarning` for :func:`sys._clear_type_cache`. This function was deprecated in Python 3.13 but it didn't raise a runtime warning. + sys.monitoring -------------- From 4b459307f1ff5b09c8d51e85c06ffaa8817c7bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Fri, 7 Feb 2025 16:41:07 +0530 Subject: [PATCH 03/11] Update Doc/deprecations/pending-removal-in-future.rst 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/deprecations/pending-removal-in-future.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index e2aa6ac9b17d42..a12ca6d0c94bb3 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -156,5 +156,5 @@ although there is currently no date scheduled for their removal. * :meth:`zipimport.zipimporter.load_module` is deprecated: use :meth:`~zipimport.zipimporter.exec_module` instead. -* :func:`sys._clear_type_cache` is deprecated. +* :func:`sys._clear_type_cache` is deprecated: use :func:`sys._clear_internal_caches` instead. From 8366a2d5a9c18e859d35d7aa0caf954b1bd65939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Fri, 7 Feb 2025 16:41:48 +0530 Subject: [PATCH 04/11] Update Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst 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> --- .../next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst b/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst index 0d8782e3cd797d..d2abf53bc0f72a 100644 --- a/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst +++ b/Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst @@ -1,2 +1,2 @@ -Raise DeprecationWarning for :func:`sys._clear_type_cache`. This function was deprecated in Python 3.13 +Raise :exc:`DeprecationWarning` for :func:`sys._clear_type_cache`. This function was deprecated in Python 3.13 but it didn't raise a runtime warning. From 0310eb2c924e9567baa4c29ecf506aebe3084361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Fri, 7 Feb 2025 16:42:36 +0530 Subject: [PATCH 05/11] Update Python/sysmodule.c 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> --- Python/sysmodule.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 966ea698ea5337..e9038138a5befe 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2147,10 +2147,11 @@ sys__clear_type_cache_impl(PyObject *module) /*[clinic end generated code: output=20e48ca54a6f6971 input=127f3e04a8d9b555]*/ { if (PyErr_WarnEx(PyExc_DeprecationWarning, - "sys._clear_type_cache() is deprecated and scheduled" - " for removal in a future version. Use the more general" - " sys._clear_internal_caches() function instead.", - 1) < 0){ + "sys._clear_type_cache() is deprecated and" + " scheduled for removal in a future version." + " Use sys._clear_internal_caches() instead.", + 1) < 0) + { return NULL; } PyType_ClearCache(); From c98e6dc6c7152672933c7f4bd1136df9a857e90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Fri, 7 Feb 2025 16:42:44 +0530 Subject: [PATCH 06/11] Update Lib/test/test_type_cache.py 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> --- Lib/test/test_type_cache.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_type_cache.py b/Lib/test/test_type_cache.py index cc2131bb3ed4f8..c22ae131cce7e2 100644 --- a/Lib/test/test_type_cache.py +++ b/Lib/test/test_type_cache.py @@ -24,6 +24,7 @@ @support.cpython_only @unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache") class TypeCacheTests(unittest.TestCase): + @ignore_deprecation def test_tp_version_tag_unique(self): """tp_version_tag should be unique assuming no overflow, even after From da4c9c18ce74c641d84e1cb054bbd378449e1df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Fri, 7 Feb 2025 16:43:05 +0530 Subject: [PATCH 07/11] Update Lib/test/test_sys.py 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> --- Lib/test/test_sys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 1f346d74ad98ac..87bc21017cc6f0 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -851,7 +851,7 @@ def test_sys_getwindowsversion_no_instantiation(self): @test.support.cpython_only def test_clear_type_cache(self): with self.assertWarnsRegex(DeprecationWarning, - r"sys._clear_type_cache\(\) is deprecated.*"): + r"sys\._clear_type_cache\(\) is deprecated.*"): sys._clear_type_cache() @force_not_colorized From bc1844e3d510bf05b3124d7ced887f7306c5f9b1 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Fri, 7 Feb 2025 17:32:26 +0530 Subject: [PATCH 08/11] Fix merge conflicts --- Lib/test/test_cmd_line.py | 13 ++++++++----- Lib/test/test_type_cache.py | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 6489969c8f7f3e..4af9f2c03eebce 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -9,9 +9,10 @@ import tempfile import textwrap import unittest +import warnings from test import support from test.support import os_helper -from test.support import force_not_colorized, warnings_helper +from test.support import force_not_colorized from test.support import threading_helper from test.support.script_helper import ( spawn_python, kill_python, assert_python_ok, assert_python_failure, @@ -932,18 +933,20 @@ def test_python_asyncio_debug(self): self.assertIn(b'True', out) @unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option") - @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_python_dump_refs(self): code = 'import sys; sys._clear_type_cache()' - rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1') + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1') self.assertEqual(rc, 0) @unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option") - @warnings_helper.ignore_warnings(category=DeprecationWarning) def test_python_dump_refs_file(self): with tempfile.NamedTemporaryFile() as dump_file: code = 'import sys; sys._clear_type_cache()' - rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFSFILE=dump_file.name) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFSFILE=dump_file.name) self.assertEqual(rc, 0) with open(dump_file.name, 'r') as file: contents = file.read() diff --git a/Lib/test/test_type_cache.py b/Lib/test/test_type_cache.py index c22ae131cce7e2..29054edca39241 100644 --- a/Lib/test/test_type_cache.py +++ b/Lib/test/test_type_cache.py @@ -1,11 +1,9 @@ """ Tests for the internal type cache in CPython. """ -import unittest import dis +import unittest +import warnings from test import support -from test.support import ( - import_helper, requires_specialization, - requires_specialization_ft, warnings_helper -) +from test.support import import_helper, requires_specialization, requires_specialization_ft try: from sys import _clear_type_cache except ImportError: @@ -18,14 +16,12 @@ type_assign_specific_version_unsafe = _testinternalcapi.type_assign_specific_version_unsafe type_assign_version = _testcapi.type_assign_version type_modified = _testcapi.type_modified -ignore_deprecation = warnings_helper.ignore_warnings(category=DeprecationWarning) @support.cpython_only @unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache") class TypeCacheTests(unittest.TestCase): - @ignore_deprecation def test_tp_version_tag_unique(self): """tp_version_tag should be unique assuming no overflow, even after clearing type cache. @@ -44,7 +40,9 @@ def test_tp_version_tag_unique(self): append_result = all_version_tags.append assertNotEqual = self.assertNotEqual for _ in range(30): - _clear_type_cache() + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + _clear_type_cache() X = type('Y', (), {}) X.x = 1 X.x @@ -67,7 +65,6 @@ class C: self.assertNotEqual(type_get_version(C), 0) self.assertNotEqual(type_get_version(C), c_ver) - @ignore_deprecation def test_type_assign_specific_version(self): """meta-test for type_assign_specific_version_unsafe""" class C: @@ -85,7 +82,9 @@ class C: new_version = type_get_version(C) self.assertEqual(new_version, orig_version + 5) - _clear_type_cache() + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + _clear_type_cache() def test_per_class_limit(self): class C: @@ -119,9 +118,11 @@ class HolderSub(Holder): @support.cpython_only class TypeCacheWithSpecializationTests(unittest.TestCase): - @ignore_deprecation + def tearDown(self): - _clear_type_cache() + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + _clear_type_cache() def _assign_valid_version_or_skip(self, type_): type_modified(type_) From bb4d5e4ac739e344493ddaedca7ecb32f86df342 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Fri, 7 Feb 2025 17:34:16 +0530 Subject: [PATCH 09/11] Remove the introduced spaces --- Lib/test/test_type_cache.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Lib/test/test_type_cache.py b/Lib/test/test_type_cache.py index 29054edca39241..f197a295df8c4c 100644 --- a/Lib/test/test_type_cache.py +++ b/Lib/test/test_type_cache.py @@ -21,7 +21,6 @@ @support.cpython_only @unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache") class TypeCacheTests(unittest.TestCase): - def test_tp_version_tag_unique(self): """tp_version_tag should be unique assuming no overflow, even after clearing type cache. @@ -117,8 +116,6 @@ class HolderSub(Holder): @support.cpython_only class TypeCacheWithSpecializationTests(unittest.TestCase): - - def tearDown(self): with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) From 160f0f7a2afc4aeb6efbd9a73f2102811d63d710 Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Fri, 7 Feb 2025 18:40:59 +0530 Subject: [PATCH 10/11] Address review comments --- Lib/test/test_cmd_line.py | 2 ++ Lib/test/test_type_cache.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py index 4af9f2c03eebce..300997246368fd 100644 --- a/Lib/test/test_cmd_line.py +++ b/Lib/test/test_cmd_line.py @@ -935,6 +935,7 @@ def test_python_asyncio_debug(self): @unittest.skipUnless(sysconfig.get_config_var('Py_TRACE_REFS'), "Requires --with-trace-refs build option") def test_python_dump_refs(self): code = 'import sys; sys._clear_type_cache()' + # TODO: Remove warnings context manager once sys._clear_type_cache is removed with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFS='1') @@ -944,6 +945,7 @@ def test_python_dump_refs(self): def test_python_dump_refs_file(self): with tempfile.NamedTemporaryFile() as dump_file: code = 'import sys; sys._clear_type_cache()' + # TODO: Remove warnings context manager once sys._clear_type_cache is removed with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) rc, out, err = assert_python_ok('-c', code, PYTHONDUMPREFSFILE=dump_file.name) diff --git a/Lib/test/test_type_cache.py b/Lib/test/test_type_cache.py index f197a295df8c4c..7469a1047f81d7 100644 --- a/Lib/test/test_type_cache.py +++ b/Lib/test/test_type_cache.py @@ -17,6 +17,10 @@ type_assign_version = _testcapi.type_assign_version type_modified = _testcapi.type_modified +def clear_type_cache(): + with warnings.catch_warnings(): + warnings.simplefilter("ignore", DeprecationWarning) + _clear_type_cache() @support.cpython_only @unittest.skipIf(_clear_type_cache is None, "requires sys._clear_type_cache") @@ -39,9 +43,7 @@ def test_tp_version_tag_unique(self): append_result = all_version_tags.append assertNotEqual = self.assertNotEqual for _ in range(30): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - _clear_type_cache() + clear_type_cache() X = type('Y', (), {}) X.x = 1 X.x @@ -81,9 +83,7 @@ class C: new_version = type_get_version(C) self.assertEqual(new_version, orig_version + 5) - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - _clear_type_cache() + clear_type_cache() def test_per_class_limit(self): class C: @@ -117,9 +117,7 @@ class HolderSub(Holder): @support.cpython_only class TypeCacheWithSpecializationTests(unittest.TestCase): def tearDown(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - _clear_type_cache() + clear_type_cache() def _assign_valid_version_or_skip(self, type_): type_modified(type_) From a19ea6bff66558e190b66122c2f00f7ae2d62caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=A4=E0=B0=BE?= =?UTF-8?q?=E0=B0=9F=E0=B0=BF=E0=B0=AA=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF?= =?UTF-8?q?=20=E0=B0=B6=E0=B1=8D=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF?= =?UTF-8?q?=E0=B0=B5=E0=B0=BE=E0=B0=B8=E0=B1=8D=20=20=E0=B0=B0=E0=B1=86?= =?UTF-8?q?=E0=B0=A1=E0=B1=8D=E0=B0=A1=E0=B0=BF=29?= Date: Mon, 17 Feb 2025 17:04:16 +0530 Subject: [PATCH 11/11] Update pending-removal-in-future.rst --- Doc/deprecations/pending-removal-in-future.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-future.rst b/Doc/deprecations/pending-removal-in-future.rst index 738c47043d87be..22f395a4923ba8 100644 --- a/Doc/deprecations/pending-removal-in-future.rst +++ b/Doc/deprecations/pending-removal-in-future.rst @@ -152,8 +152,5 @@ although there is currently no date scheduled for their removal. will always return ``True``. Prefer explicit ``len(elem)`` or ``elem is not None`` tests instead. -* :meth:`zipimport.zipimporter.load_module` is deprecated: - use :meth:`~zipimport.zipimporter.exec_module` instead. - * :func:`sys._clear_type_cache` is deprecated: - use :func:`sys._clear_internal_caches` instead. \ No newline at end of file + use :func:`sys._clear_internal_caches` instead.