From 299692afd8b8520383e6badeb907b285fc7c0909 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 6 May 2022 05:24:29 +0200 Subject: [PATCH] gh-88279: Deprecate PySys_SetArgvEx() (#92363) Deprecate the following C functions: * PySys_SetArgv() * PySys_SetArgvEx() * PySys_SetPath() --- Doc/c-api/init.rst | 13 +++++++++++++ Doc/c-api/intro.rst | 8 +++----- Doc/c-api/sys.rst | 7 +++++++ Doc/whatsnew/3.11.rst | 5 ++++- Include/sysmodule.h | 6 +++--- .../2022-05-06-04-55-17.gh-issue-88279.3mQ54t.rst | 2 ++ 6 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 Misc/NEWS.d/next/C API/2022-05-06-04-55-17.gh-issue-88279.3mQ54t.rst diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index c17379c52ab..d4954958f85 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -616,6 +616,11 @@ Process-wide parameters single: Py_FatalError() single: argv (in module sys) + This API is kept for backward compatibility: setting + :c:member:`PyConfig.argv`, :c:member:`PyConfig.parse_argv` and + :c:member:`PyConfig.safe_path` should be used instead, see :ref:`Python + Initialization Configuration `. + Set :data:`sys.argv` based on *argc* and *argv*. These parameters are similar to those passed to the program's :c:func:`main` function with the difference that the first entry should refer to the script file to be @@ -659,9 +664,15 @@ Process-wide parameters .. XXX impl. doesn't seem consistent in allowing ``0``/``NULL`` for the params; check w/ Guido. + .. deprecated:: 3.11 + .. c:function:: void PySys_SetArgv(int argc, wchar_t **argv) + This API is kept for backward compatibility: setting + :c:member:`PyConfig.argv` and :c:member:`PyConfig.parse_argv` should be used + instead, see :ref:`Python Initialization Configuration `. + This function works like :c:func:`PySys_SetArgvEx` with *updatepath* set to ``1`` unless the :program:`python` interpreter was started with the :option:`-I`. @@ -674,6 +685,8 @@ Process-wide parameters .. versionchanged:: 3.4 The *updatepath* value depends on :option:`-I`. + .. deprecated:: 3.11 + .. c:function:: void Py_SetPythonHome(const wchar_t *home) diff --git a/Doc/c-api/intro.rst b/Doc/c-api/intro.rst index 3e7890cb766..9efac0b83d0 100644 --- a/Doc/c-api/intro.rst +++ b/Doc/c-api/intro.rst @@ -709,12 +709,10 @@ the table of loaded modules, and creates the fundamental modules :mod:`builtins`, :mod:`__main__`, and :mod:`sys`. It also initializes the module search path (``sys.path``). -.. index:: single: PySys_SetArgvEx() - :c:func:`Py_Initialize` does not set the "script argument list" (``sys.argv``). -If this variable is needed by Python code that will be executed later, it must -be set explicitly with a call to ``PySys_SetArgvEx(argc, argv, updatepath)`` -after the call to :c:func:`Py_Initialize`. +If this variable is needed by Python code that will be executed later, setting +:c:member:`PyConfig.argv` and :c:member:`PyConfig.parse_argv` must be set: see +:ref:`Python Initialization Configuration `. On most systems (in particular, on Unix and Windows, although the details are slightly different), :c:func:`Py_Initialize` calculates the module search path diff --git a/Doc/c-api/sys.rst b/Doc/c-api/sys.rst index 66216eee6d0..5e8d993100f 100644 --- a/Doc/c-api/sys.rst +++ b/Doc/c-api/sys.rst @@ -264,10 +264,17 @@ accessible to C code. They all work with the current interpreter thread's .. c:function:: void PySys_SetPath(const wchar_t *path) + This API is kept for backward compatibility: setting + :c:member:`PyConfig.module_search_paths` and + :c:member:`PyConfig.module_search_paths_set` should be used instead, see + :ref:`Python Initialization Configuration `. + Set :data:`sys.path` to a list object of paths found in *path* which should be a list of paths separated with the platform's search path delimiter (``:`` on Unix, ``;`` on Windows). + .. deprecated:: 3.11 + .. c:function:: void PySys_WriteStdout(const char *format, ...) Write the output string described by *format* to :data:`sys.stdout`. No diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index c84b36f8d6c..822cb8b1f0f 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1742,6 +1742,9 @@ Deprecated * :c:func:`PySys_AddWarnOption` * :c:func:`PySys_AddXOption` * :c:func:`PySys_HasWarnOptions` + * :c:func:`PySys_SetArgvEx` + * :c:func:`PySys_SetArgv` + * :c:func:`PySys_SetPath` * :c:func:`Py_SetPath` * :c:func:`Py_SetProgramName` * :c:func:`Py_SetPythonHome` @@ -1750,7 +1753,7 @@ Deprecated Use the new :c:type:`PyConfig` API of the :ref:`Python Initialization Configuration ` instead (:pep:`587`). - (Contributed by Victor Stinner in :issue:`44113`.) + (Contributed by Victor Stinner in :gh:`88279`.) * Deprecate the ``ob_shash`` member of the :c:type:`PyBytesObject`. Use :c:func:`PyObject_Hash` instead. (Contributed by Inada Naoki in :issue:`46864`.) diff --git a/Include/sysmodule.h b/Include/sysmodule.h index 3463c622309..b5087119b1c 100644 --- a/Include/sysmodule.h +++ b/Include/sysmodule.h @@ -10,9 +10,9 @@ extern "C" { PyAPI_FUNC(PyObject *) PySys_GetObject(const char *); PyAPI_FUNC(int) PySys_SetObject(const char *, PyObject *); -PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **); -PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int); -PyAPI_FUNC(void) PySys_SetPath(const wchar_t *); +Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **); +Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgvEx(int, wchar_t **, int); +Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetPath(const wchar_t *); PyAPI_FUNC(void) PySys_WriteStdout(const char *format, ...) Py_GCC_ATTRIBUTE((format(printf, 1, 2))); diff --git a/Misc/NEWS.d/next/C API/2022-05-06-04-55-17.gh-issue-88279.3mQ54t.rst b/Misc/NEWS.d/next/C API/2022-05-06-04-55-17.gh-issue-88279.3mQ54t.rst new file mode 100644 index 00000000000..eb448f994e8 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-05-06-04-55-17.gh-issue-88279.3mQ54t.rst @@ -0,0 +1,2 @@ +Deprecate the C functions: :c:func:`PySys_SetArgv`, +:c:func:`PySys_SetArgvEx`, :c:func:`PySys_SetPath`. Patch by Victor Stinner.