Skip to content

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

Merged
hugovk merged 13 commits into
python:mainfrom
srinivasreddy:gh-129027
Apr 25, 2025
Merged

gh-129027: Raise DeprecationWarning for sys._clear_type_cache#129043
hugovk merged 13 commits into
python:mainfrom
srinivasreddy:gh-129027

Conversation

@srinivasreddy

@srinivasreddy srinivasreddy commented Jan 20, 2025

Copy link
Copy Markdown
Contributor

Comment thread Lib/test/test_sys.py Outdated
Comment thread Lib/test/test_sys.py Outdated

@tomasr8 tomasr8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sys._clear_type_cache is used in other tests as well which will now raise a DeprecationWarning. I think we should suppress the warnings in the relevant tests (or maybe switch to sys._clear_internal_caches()? though that might make backporting tests to 3.12 more difficult since the function was added in 3.13)

Comment thread Python/sysmodule.c Outdated
@tomasr8

tomasr8 commented Jan 20, 2025

Copy link
Copy Markdown
Member

This will also require a news entry :)

@srinivasreddy

srinivasreddy commented Jan 21, 2025

Copy link
Copy Markdown
Contributor Author

@tomasr8 Addressed in c532328

Comment thread Lib/test/test_sys.py Outdated
Comment thread Lib/test/test_type_cache.py Outdated
Comment thread Python/sysmodule.c Outdated
Comment thread Python/sysmodule.c Outdated
Comment thread Python/sysmodule.c Outdated
Comment thread Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst Outdated
Comment thread Python/sysmodule.c Outdated

@tomasr8 tomasr8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you also like to add a What's New entry as @picnixz suggested?

Comment thread Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst Outdated
@srinivasreddy

srinivasreddy commented Jan 30, 2025

Copy link
Copy Markdown
Contributor Author

@tomasr8 Thanks 👍🏾 . Please review again?

@srinivasreddy srinivasreddy requested a review from tomasr8 January 30, 2025 09:30
@picnixz

picnixz commented Feb 1, 2025

Copy link
Copy Markdown
Member

The What's New is still missing (it's something that you need to add in Doc/whatsnew/3.14.rst I think). The NEWS (blurb) entry is only for the full changelog, but deprecation notices are also communicated there so that they have better visibility. You can put this change in the Pending Removal section (as we are now emitting a warning)

@picnixz

picnixz commented Feb 7, 2025

Copy link
Copy Markdown
Member

I'll review it in a few minutes, but I have some comments on some wording. And I think we already mentioned to avoid force pushing, so please do so in the future. Avoid rebasing to merge upstream and prefer using the update button instead. Or if it becomes too messy, just create a new branch to be sure you don't trigger unnecessary review requests

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After commenting the files, I think you can create a wrapper around _clear_type_cache that suppresses its deprecation warning use instead of suppressing the warning around the entire test. If other deprecation warnings appear we want them to be printed.

Comment thread Doc/deprecations/pending-removal-in-future.rst Outdated
Comment thread Doc/whatsnew/3.14.rst
Comment thread Python/sysmodule.c
Comment thread Misc/NEWS.d/next/Library/2025-01-21-11-48-19.gh-issue-129027.w0vxzZ.rst Outdated
Comment thread Lib/test/test_type_cache.py Outdated
Comment thread Lib/test/test_type_cache.py Outdated
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a dummy decorator if _clear_type_cache is None.

Comment thread Lib/test/test_sys.py Outdated
Comment thread Lib/test/test_cmd_line.py Outdated
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use this one only when doing assert_python_ok?

Comment thread Lib/test/test_cmd_line.py Outdated
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto

Comment thread Lib/test/test_type_cache.py Outdated
self.assertNotEqual(type_get_version(C), 0)
self.assertNotEqual(type_get_version(C), c_ver)

@ignore_deprecation

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we only protect the _clear_type_cache call instead of the entire test?

srinivasreddy and others added 8 commits February 7, 2025 16:40
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…0vxzZ.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@srinivasreddy

Copy link
Copy Markdown
Contributor Author

@picnixz Please review again.

Comment thread Lib/test/test_cmd_line.py
Comment thread Lib/test/test_cmd_line.py
Comment thread Lib/test/test_type_cache.py Outdated
Comment on lines +42 to +43
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)

Copy link
Copy Markdown
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()

@srinivasreddy

Copy link
Copy Markdown
Contributor Author

@picnixz Done.

@tomasr8

tomasr8 commented Feb 17, 2025

Copy link
Copy Markdown
Member

@srinivasreddy There are some conflicts with main now, could you fix them please?

@srinivasreddy

Copy link
Copy Markdown
Contributor Author

@tomasr8 Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants