[Python-checkins] bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)

Miss Islington (bot) webhook-mailer at python.org
Sat Feb 17 02:14:44 EST 2018


https://github.com/python/cpython/commit/dda938683c48197ab7e775144136f433a5d43103
commit: dda938683c48197ab7e775144136f433a5d43103
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-02-16T23:14:41-08:00
summary:

bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)

(cherry picked from commit 9f4223261fd129ad7b9a09b2b0d625d1bb90b22b)

Co-authored-by: Kyle Altendorf <sda at fstab.net>

files:
A Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst
M Lib/test/test_trace.py
M Lib/trace.py

diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 1d87aea5a3d3..e04ca01c4299 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -387,5 +387,15 @@ def test_listfuncs_flag_success(self):
             status, stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
             self.assertIn(b'functions called:', stdout)
 
+    def test_sys_argv_list(self):
+        with open(TESTFN, 'w') as fd:
+            self.addCleanup(unlink, TESTFN)
+            fd.write("import sys\n")
+            fd.write("print(type(sys.argv))\n")
+
+        status, direct_stdout, stderr = assert_python_ok(TESTFN)
+        status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
+        self.assertIn(direct_stdout.strip(), trace_stdout)
+
 if __name__ == '__main__':
     unittest.main()
diff --git a/Lib/trace.py b/Lib/trace.py
index ae154615fa3a..9ba9486bd024 100755
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -710,7 +710,7 @@ def parse_ignore_dir(s):
     if opts.filename is None:
         parser.error('filename is missing: required with the main options')
 
-    sys.argv = opts.filename, *opts.arguments
+    sys.argv = [opts.filename, *opts.arguments]
     sys.path[0] = os.path.dirname(opts.filename)
 
     t = Trace(opts.count, opts.trace, countfuncs=opts.listfuncs,
diff --git a/Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst b/Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst
new file mode 100644
index 000000000000..8eabbfaea222
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-02-15-12-04-29.bpo-32852.HDqIxM.rst
@@ -0,0 +1 @@
+Make sure sys.argv remains as a list when running trace.



More information about the Python-checkins mailing list