Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-129027: Raise DeprecationWarning for sys._clear_type_cache#129043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
hugovk merged 13 commits intopython:mainfromsrinivasreddy:gh-129027
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
bac8a24
gh-129027: Raise DeprecationWarning for sys._clear_type_cache
srinivasreddyFeb 7, 2025
3d2bca7
Update Doc/whatsnew/3.14.rst
srinivasreddyFeb 7, 2025
4b45930
Update Doc/deprecations/pending-removal-in-future.rst
srinivasreddyFeb 7, 2025
8366a2d
Update Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w…
srinivasreddyFeb 7, 2025
0310eb2
Update Python/sysmodule.c
srinivasreddyFeb 7, 2025
c98e6dc
Update Lib/test/test_type_cache.py
srinivasreddyFeb 7, 2025
da4c9c1
Update Lib/test/test_sys.py
srinivasreddyFeb 7, 2025
bc1844e
Fix merge conflicts
srinivasreddyFeb 7, 2025
bb4d5e4
Remove the introduced spaces
srinivasreddyFeb 7, 2025
160f0f7
Address review comments
srinivasreddyFeb 7, 2025
aa1cc67
Merge branch 'main' into gh-129027
srinivasreddyFeb 17, 2025
a19ea6b
Update pending-removal-in-future.rst
srinivasreddyFeb 17, 2025
edb99cf
Merge branch 'main' into gh-129027
hugovkApr 24, 2025
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 deletionsDoc/deprecations/pending-removal-in-future.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -153,3 +153,6 @@ although there is currently no date scheduled for their removal.
:class:`~xml.etree.ElementTree.Element` is deprecated. In a future release it
will always return ``True``. Prefer explicit ``len(elem)`` or
``elem is not None`` tests instead.

* :func:`sys._clear_type_cache` is deprecated:
use :func:`sys._clear_internal_caches` instead.
3 changes: 3 additions & 0 deletionsDoc/whatsnew/3.14.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1203,6 +1203,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
11 changes: 9 additions & 2 deletionsLib/test/test_cmd_line.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand Up@@ -936,14 +937,20 @@ 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')
# 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')
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)
# 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)
self.assertEqual(rc, 0)
with open(dump_file.name, 'r') as file:
contents = file.read()
Expand Down
4 changes: 3 additions & 1 deletionLib/test/test_sys.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -891,7 +891,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
13 changes: 9 additions & 4 deletionsLib/test/test_type_cache.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 All@@ -16,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")
Expand All@@ -38,7 +43,7 @@ def test_tp_version_tag_unique(self):
append_result = all_version_tags.append
assertNotEqual = self.assertNotEqual
for _ in range(30):
_clear_type_cache()
clear_type_cache()
X = type('Y', (), {})
X.x = 1
X.x
Expand DownExpand Up@@ -78,7 +83,7 @@ class C:
new_version = type_get_version(C)
self.assertEqual(new_version, orig_version + 5)

_clear_type_cache()
clear_type_cache()

def test_per_class_limit(self):
class C:
Expand DownExpand Up@@ -112,7 +117,7 @@ class HolderSub(Holder):
@support.cpython_only
class TypeCacheWithSpecializationTests(unittest.TestCase):
def tearDown(self):
_clear_type_cache()
clear_type_cache()

def _assign_valid_version_or_skip(self, type_):
type_modified(type_)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsPython/sysmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2208,6 +2208,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

[8]ページ先頭

©2009-2025 Movatter.jp