From baf747051557d029bc807d08470279490a04c8e1 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 15 Sep 2025 12:01:33 +0300 Subject: [PATCH] gh-138886: Remove deprecated `PySys_ResetWarnOptions` C-API function (#138887) --- Doc/c-api/init.rst | 1 - Doc/c-api/sys.rst | 8 -------- Doc/data/stable_abi.dat | 1 - Doc/deprecations/c-api-pending-removal-in-3.15.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- Doc/whatsnew/3.15.rst | 5 +++++ Include/sysmodule.h | 2 -- Misc/NEWS.d/3.13.0a1.rst | 2 +- .../C_API/2025-09-14-13-09-47.gh-issue-138886.dlcTXL.rst | 1 + Misc/stable_abi.toml | 1 + Programs/_testembed.c | 4 ++++ Python/sysmodule.c | 2 +- 12 files changed, 15 insertions(+), 16 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-09-14-13-09-47.gh-issue-138886.dlcTXL.rst diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index bb9e08acee..379330f380 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -41,7 +41,6 @@ The following functions can be safely called before Python is initialized: * :c:func:`PyObject_SetArenaAllocator` * :c:func:`Py_SetProgramName` * :c:func:`Py_SetPythonHome` - * :c:func:`PySys_ResetWarnOptions` * the configuration functions covered in :ref:`init-config` * Informative functions: diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index b34936dd55..9a5e26d231 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -316,14 +316,6 @@ accessible to C code. They all work with the current interpreter thread's case *name* is deleted from the sys module. Returns ``0`` on success, ``-1`` on error. -.. c:function:: void PySys_ResetWarnOptions() - - Reset :data:`sys.warnoptions` to an empty list. This function may be - called prior to :c:func:`Py_Initialize`. - - .. deprecated-removed:: 3.13 3.15 - Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. - .. c:function:: void PySys_WriteStdout(const char *format, ...) Write the output string described by *format* to :data:`sys.stdout`. No diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 641f7bb380..3f51254494 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -637,7 +637,6 @@ func,PySys_GetObject,3.2,, func,PySys_GetOptionalAttr,3.15,, func,PySys_GetOptionalAttrString,3.15,, func,PySys_GetXOptions,3.7,, -func,PySys_ResetWarnOptions,3.2,, func,PySys_SetArgv,3.2,, func,PySys_SetArgvEx,3.2,, func,PySys_SetObject,3.2,, diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst index a3e335ecaf..8db3631cab 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -59,7 +59,7 @@ Pending removal in Python 3.15 Set :c:member:`PyConfig.program_name` instead. * :c:func:`!Py_SetPythonHome()`: Set :c:member:`PyConfig.home` instead. - * :c:func:`PySys_ResetWarnOptions`: + * :c:func:`!PySys_ResetWarnOptions`: Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. The :c:func:`Py_InitializeFromConfig` API should be used with diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 6545da66af..67fec4ebc4 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -2490,7 +2490,7 @@ Deprecated C APIs * Deprecate old Python initialization functions: - * :c:func:`PySys_ResetWarnOptions`: + * :c:func:`!PySys_ResetWarnOptions`: Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. * :c:func:`!Py_GetExecPrefix`: Get :data:`sys.exec_prefix` instead. diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 9031301989..ed44558c1d 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -815,6 +815,11 @@ Removed C APIs of :c:func:`PyImport_ImportModule`. (Contributed by Bénédikt Tran in :gh:`133644`.) +* Remove deprecated :c:func:`!PySys_ResetWarnOptions`. + Clear :data:`sys.warnoptions` and :data:`!warnings.filters` instead. + + (Contributed by Nikita Sobolev in :gh:`138886`.) + The following functions are removed in favor of :c:func:`PyConfig_Get`. The |pythoncapi_compat_project| can be used to get :c:func:`!PyConfig_Get` on Python 3.13 and older. diff --git a/Include/sysmodule.h b/Include/sysmodule.h index 2f36279179..b7d800c5e5 100644 --- a/Include/sysmodule.h +++ b/Include/sysmodule.h @@ -23,8 +23,6 @@ PyAPI_FUNC(void) PySys_WriteStderr(const char *format, ...) PyAPI_FUNC(void) PySys_FormatStdout(const char *format, ...); PyAPI_FUNC(void) PySys_FormatStderr(const char *format, ...); -Py_DEPRECATED(3.13) PyAPI_FUNC(void) PySys_ResetWarnOptions(void); - PyAPI_FUNC(PyObject *) PySys_GetXOptions(void); #ifdef __cplusplus diff --git a/Misc/NEWS.d/3.13.0a1.rst b/Misc/NEWS.d/3.13.0a1.rst index 0741eab4ec..a3aa7353a1 100644 --- a/Misc/NEWS.d/3.13.0a1.rst +++ b/Misc/NEWS.d/3.13.0a1.rst @@ -6592,7 +6592,7 @@ functions, deprecated in Python 3.9. Patch by Victor Stinner. Deprecate old Python initialization functions: -* :c:func:`PySys_ResetWarnOptions` +* :c:func:`!PySys_ResetWarnOptions` * :c:func:`!Py_GetExecPrefix` * :c:func:`!Py_GetPath` * :c:func:`!Py_GetPrefix` diff --git a/Misc/NEWS.d/next/C_API/2025-09-14-13-09-47.gh-issue-138886.dlcTXL.rst b/Misc/NEWS.d/next/C_API/2025-09-14-13-09-47.gh-issue-138886.dlcTXL.rst new file mode 100644 index 0000000000..a77f42977a --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-09-14-13-09-47.gh-issue-138886.dlcTXL.rst @@ -0,0 +1 @@ +Remove deprecated :c:func:`!PySys_ResetWarnOptions` C-API function. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index bc0fab4852..d651e0fac1 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1335,6 +1335,7 @@ abi_only = true [function.PySys_ResetWarnOptions] added = '3.2' + abi_only = true [function.PySys_SetArgv] added = '3.2' [function.PySys_SetArgvEx] diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 28c004c3c5..4f5a14b8ca 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -22,6 +22,10 @@ extern void PySys_AddWarnOption(const wchar_t *s); extern void PySys_AddXOption(const wchar_t *s); extern void Py_SetPath(const wchar_t *path); +// These functions were removed from Python 3.15 API but are still exported +// for the stable ABI. We want to test them in this program. +extern void PySys_ResetWarnOptions(void); + int main_argc; char **main_argv; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 832d2afff8..59baca2679 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3045,7 +3045,7 @@ get_warnoptions(PyThreadState *tstate) return warnoptions; } -void +PyAPI_FUNC(void) PySys_ResetWarnOptions(void) { PyThreadState *tstate = _PyThreadState_GET();