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/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 194128e..aaba663 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -434,6 +434,11 @@
def test_attributes(self):
self.assertIsInstance(sys.api_version, int)
self.assertIsInstance(sys.argv, list)
+ for arg in sys.argv:
+ self.assertIsInstance(arg, str)
+ self.assertIsInstance(sys.orig_argv, list)
+ for arg in sys.orig_argv:
+ self.assertIsInstance(arg, str)
self.assertIn(sys.byteorder, ("little", "big"))
self.assertIsInstance(sys.builtin_module_names, tuple)
self.assertIsInstance(sys.copyright, str)
@@ -930,6 +935,21 @@
out = out.decode('ascii', 'replace').rstrip()
self.assertEqual(out, 'mbcs replace')
+ def test_orig_argv(self):
+ code = textwrap.dedent('''
+ import sys
+ print(sys.argv)
+ print(sys.orig_argv)
+ ''')
+ args = [sys.executable, '-I', '-X', 'utf8', '-c', code, 'arg']
+ proc = subprocess.run(args, check=True, capture_output=True, text=True)
+ expected = [
+ repr(['-c', 'arg']), # sys.argv
+ repr(args), # sys.orig_argv
+ ]
+ self.assertEqual(proc.stdout.rstrip().splitlines(), expected,
+ proc)
+
@test.support.cpython_only
class UnraisableHookTest(unittest.TestCase):