[New-bugs-announce] [issue32852] trace changes sys.argv from list to tuple

Kyle Altendorf report at bugs.python.org
Thu Feb 15 11:39:05 EST 2018


New submission from Kyle Altendorf <sda at fstab.net>:

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)

----------
components: Library (Lib)
messages: 312213
nosy: altendky
priority: normal
severity: normal
status: open
title: trace changes sys.argv from list to tuple
versions: Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32852>
_______________________________________


More information about the New-bugs-announce mailing list