bpo-23427: Add sys.orig_argv attribute (GH-20729)
Add sys.orig_argv attribute: the list of the original command line
arguments passed to the Python executable.
Rename also PyConfig._orig_argv to PyConfig.orig_argv and
document it.
diff --git a/Doc/c-api/init_config.rst b/Doc/c-api/init_config.rst
index 9b0728d..84064d9 100644
--- a/Doc/c-api/init_config.rst
+++ b/Doc/c-api/init_config.rst
@@ -424,6 +424,8 @@
:c:member:`~PyConfig.argv` is empty, an empty string is added to ensure
that :data:`sys.argv` always exists and is never empty.
+ See also the :c:member:`~PyConfig.orig_argv` member.
+
.. c:member:: wchar_t* base_exec_prefix
:data:`sys.base_exec_prefix`.
@@ -586,6 +588,23 @@
* 1: Remove assertions, set ``__debug__`` to ``False``
* 2: Strip docstrings
+ .. c:member:: PyWideStringList orig_argv
+
+ The list of the original command line arguments passed to the Python
+ executable.
+
+ If :c:member:`~PyConfig.orig_argv` list is empty and
+ :c:member:`~PyConfig.argv` is not a list only containing an empty
+ string, :c:func:`PyConfig_Read()` copies :c:member:`~PyConfig.argv` into
+ :c:member:`~PyConfig.orig_argv` before modifying
+ :c:member:`~PyConfig.argv` (if :c:member:`~PyConfig.parse_argv` is
+ non-zero).
+
+ See also the :c:member:`~PyConfig.argv` member and the
+ :c:func:`Py_GetArgcArgv` function.
+
+ .. versionadded:: 3.10
+
.. c:member:: int parse_argv
If non-zero, parse :c:member:`~PyConfig.argv` the same way the regular
@@ -982,6 +1001,8 @@
Get the original command line arguments, before Python modified them.
+ See also :c:member:`PyConfig.orig_argv` member.
+
Multi-Phase Initialization Private Provisional API
--------------------------------------------------
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index 880f252..d201d70 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -66,6 +66,8 @@
To loop over the standard input, or the list of files given on the
command line, see the :mod:`fileinput` module.
+ See also :data:`sys.orig_argv`.
+
.. note::
On Unix, command line arguments are passed by bytes from OS. Python decodes
them with filesystem encoding and "surrogateescape" error handler.
@@ -1037,6 +1039,16 @@
deleting essential items from the dictionary may cause Python to fail.
+.. data:: orig_argv
+
+ The list of the original command line arguments passed to the Python
+ executable.
+
+ See also :data:`sys.argv`.
+
+ .. versionadded:: 3.10
+
+
.. data:: path
.. index:: triple: module; search; path
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 0c4ff02..a755d26 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -110,6 +110,13 @@
:func:`~glob.iglob` which allow to specify the root directory for searching.
(Contributed by Serhiy Storchaka in :issue:`38144`.)
+sys
+---
+
+Add :data:`sys.orig_argv` attribute: the list of the original command line
+arguments passed to the Python executable.
+(Contributed by Victor Stinner in :issue:`23427`.)
+
Optimizations
=============
@@ -150,10 +157,14 @@
New Features
------------
- The result of :c:func:`PyNumber_Index` now always has exact type :class:`int`.
+* The result of :c:func:`PyNumber_Index` now always has exact type :class:`int`.
Previously, the result could have been an instance of a subclass of ``int``.
(Contributed by Serhiy Storchaka in :issue:`40792`.)
+* Add a new :c:member:`~PyConfig.orig_argv` member to the :c:type:`PyConfig`
+ structure: the list of the original command line arguments passed to the
+ Python executable.
+ (Contributed by Victor Stinner in :issue:`23427`.)
Porting to Python 3.10
----------------------