classification
Title: trace changes sys.argv from list to tuple
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: altendky, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-02-15 16:39 by altendky, last changed 2018-02-17 08:03 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5692 merged altendky, 2018-02-15 17:13
PR 5702 closed altendky, 2018-02-16 20:37
PR 5703 closed altendky, 2018-02-16 20:38
PR 5704 closed altendky, 2018-02-16 21:04
PR 5705 closed altendky, 2018-02-16 21:04
PR 5719 merged miss-islington, 2018-02-17 06:33
PR 5720 merged miss-islington, 2018-02-17 06:34
Messages (5)
msg312213 - (view) Author: Kyle Altendorf (altendky) * Date: 2018-02-15 16:39
Normally sys.argv is a list but when using the trace module sys.argv gets changed to a tuple.  In my case this caused an issue with running an entry point due to the line:

  sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])

When researching I found:
  https://stackoverflow.com/questions/47688568/trace-sys-argv-args-typeerror-tuple-object-does-not-support-item-assig

They point out where trace assigns a tuple to sys.argv.
  https://github.com/python/cpython/blob/master/Lib/trace.py#L708


I'll see what I can do to put together a quick patch.


$ cat t.py
import sys

print(sys.version)

print(type(sys.argv))
$ /home/altendky/.pyenv/versions/3.7.0a2/bin/python t.py
3.7.0a2 (default, Feb 15 2018, 11:20:36) 
[GCC 6.3.0 20170516]
<class 'list'>
$ /home/altendky/.pyenv/versions/3.7.0a2/bin/python -m trace --trace t.py
 --- modulename: t, funcname: <module>
t.py(1): import sys
t.py(3): print(sys.version)
3.7.0a2 (default, Feb 15 2018, 11:20:36) 
[GCC 6.3.0 20170516]
t.py(5): print(type(sys.argv))
<class 'tuple'>
 --- modulename: trace, funcname: _unsettrace
trace.py(71):     sys.settrace(None)
msg312271 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-17 06:32
New changeset 9f4223261fd129ad7b9a09b2b0d625d1bb90b22b by Serhiy Storchaka (Kyle Altendorf) in branch 'master':
bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)
https://github.com/python/cpython/commit/9f4223261fd129ad7b9a09b2b0d625d1bb90b22b
msg312272 - (view) Author: miss-islington (miss-islington) Date: 2018-02-17 06:53
New changeset afb5e5583694798793d44f35f901aa912ece278a by Miss Islington (bot) in branch '3.7':
bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)
https://github.com/python/cpython/commit/afb5e5583694798793d44f35f901aa912ece278a
msg312273 - (view) Author: miss-islington (miss-islington) Date: 2018-02-17 07:14
New changeset dda938683c48197ab7e775144136f433a5d43103 by Miss Islington (bot) in branch '3.6':
bpo-32852: Fix trace changing sys.argv to tuple. (GH-5692)
https://github.com/python/cpython/commit/dda938683c48197ab7e775144136f433a5d43103
msg312274 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-02-17 08:03
Thank you for your contribution Kyle.

Usually backports a made after merging the original PR. Thanks to bots this is done in half-automatical way.
History
Date User Action Args
2018-02-17 08:03:25serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg312274

stage: patch review -> resolved
2018-02-17 07:14:43miss-islingtonsetmessages: + msg312273
2018-02-17 06:53:26miss-islingtonsetnosy: + miss-islington
messages: + msg312272
2018-02-17 06:34:46miss-islingtonsetpull_requests: + pull_request5507
2018-02-17 06:33:53miss-islingtonsetpull_requests: + pull_request5506
2018-02-17 06:32:42serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg312271
2018-02-16 21:04:52altendkysetpull_requests: + pull_request5494
2018-02-16 21:04:45altendkysetpull_requests: + pull_request5493
2018-02-16 20:38:22altendkysetpull_requests: + pull_request5492
2018-02-16 20:37:53altendkysetpull_requests: + pull_request5491
2018-02-16 20:17:41altendkysetversions: + Python 3.8
2018-02-15 17:13:29altendkysetkeywords: + patch
stage: patch review
pull_requests: + pull_request5485
2018-02-15 16:39:05altendkycreate