Fix deprecated PyErr_Fetch/PyErr_Restore in close_file_callback#31610
Open
kx7m2qd wants to merge 1 commit intomatplotlib:mainfrom
Open
Fix deprecated PyErr_Fetch/PyErr_Restore in close_file_callback#31610kx7m2qd wants to merge 1 commit intomatplotlib:mainfrom
kx7m2qd wants to merge 1 commit intomatplotlib:mainfrom
Conversation
story645
reviewed
May 4, 2026
9876779 to
94738e5
Compare
Replace deprecated PyErr_Fetch/PyErr_Restore (deprecated in Python 3.12) with PyErr_GetRaisedException/PyErr_SetRaisedException on Python 3.12+, while keeping backward compatibility with older versions via #if guard. Closes part of matplotlib#31424
94738e5 to
c1232d8
Compare
QuLogic
reviewed
May 8, 2026
| close(); | ||
| } | ||
|
|
||
| // FIX: Guard against NULL family_name pointers before streaming. |
Member
There was a problem hiding this comment.
Both these comments are not really necessary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace deprecated PyErr_Fetch/PyErr_Restore in close_file_callback
PyErr_FetchandPyErr_Restorewere deprecated in Python 3.12 in favour ofthe unified
PyErr_GetRaisedException/PyErr_SetRaisedExceptionAPI.This PR updates
close_file_callbackinsrc/ft2font_wrapper.cppto use thenew API on Python 3.12+, while keeping the old API for older versions via a
#if PY_VERSION_HEX >= 0x030c0000guard.Closes part of #31424
PR summary
PyErr_Fetch/PyErr_Restorewere deprecated in Python 3.12 (seehttps://docs.python.org/3/whatsnew/3.12.html#deprecated). The replacement is
the simpler single-object API:
PyErr_GetRaisedException/PyErr_SetRaisedException.The change is in
close_file_callbackinsrc/ft2font_wrapper.cpp(lines ~394and ~402 as noted in #31424). A version guard ensures backward compatibility
with Python < 3.12.
No behavior change — this is a pure maintenance fix to silence deprecation
warnings and future-proof the code for Python 3.13+.
AI Disclosure
Used Claude (Anthropic) to help identify the correct replacement API and version
guard approach. The fix, testing, and final review were done manually.
PR checklist
lib/matplotlib/tests/test_ft2font.py; 2 skips are pre-existing and unrelated to this change