Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Doc/deprecations/pending-removal-in-future.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,9 @@ 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
--------------
Expand Down
9 changes: 7 additions & 2 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -934,14 +935,18 @@ 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()'
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")
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()
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 11 additions & 4 deletions Lib/test/test_type_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" 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
try:
Expand Down Expand Up @@ -38,7 +39,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can wrap clear_type_cache with a waraning filter:

def clear_type_cache():
    with warnings.catch_warnings():
       ...
       _clear_type_cache()

_clear_type_cache()
X = type('Y', (), {})
X.x = 1
X.x
Expand Down Expand Up @@ -78,7 +81,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:
Expand Down Expand Up @@ -112,7 +117,9 @@ class HolderSub(Holder):
@support.cpython_only
class TypeCacheWithSpecializationTests(unittest.TestCase):
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_)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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.
8 changes: 8 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,14 @@ 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 sys._clear_internal_caches() instead.",
1) < 0)
{
return NULL;
}
PyType_ClearCache();
Py_RETURN_NONE;
}
Expand Down
Loading