classification
Title: regression in pdb output between 2.7 and 3.5
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: doughellmann, gvanrossum, iritkatriel, miss-islington, taleinat, vstinner, xdegaye
Priority: normal Keywords: 3.5regression, patch

Created on 2016-01-08 23:43 by doughellmann, last changed 2021-04-02 11:39 by iritkatriel. This issue is now closed.

Files
File name Uploaded Description Edit
pdb_run.py doughellmann, 2016-01-08 23:43
Pull Requests
URL Status Linked Edit
PR 22033 merged iritkatriel, 2020-08-31 19:40
PR 25139 merged iritkatriel, 2021-04-01 16:01
PR 25149 merged iritkatriel, 2021-04-02 10:40
PR 25150 merged miss-islington, 2021-04-02 11:17
Messages (14)
msg257785 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2016-01-08 23:43
Under python 2.7 using the "run" command within pdb and passing it arguments causes those arguments to be printed out. Under 3.5, this is no longer true.



$ python2.7 -m pdb pdb_run.py
> /Users/dhellmann/Dropbox/PyMOTW/Python3/pymotw-3/source/pdb/pdb_run.py(7)<module>()
-> import sys
(Pdb) c
('Command-line args:', ['pdb_run.py'])
The program finished and will be restarted
> /Users/dhellmann/Dropbox/PyMOTW/Python3/pymotw-3/source/pdb/pdb_run.py(7)<module>()
-> import sys
(Pdb) run a b c "this is a long argument"
Restarting pdb_run.py with arguments:
	a b c this is a long argument
> /Users/dhellmann/Dropbox/PyMOTW/Python3/pymotw-3/source/pdb/pdb_run.py(7)<module>()
-> import sys



$ python3.5 -m pdb pdb_run.py
> /Users/dhellmann/Dropbox/PyMOTW/Python3/pymotw-3/source/pdb/pdb_run.py(7)<module>()
-> import sys
(Pdb) c
Command-line args: ['pdb_run.py']
The program finished and will be restarted
> /Users/dhellmann/Dropbox/PyMOTW/Python3/pymotw-3/source/pdb/pdb_run.py(7)<module>()
-> import sys
(Pdb) run a b c "this is a long argument"
Restarting pdb_run.py with arguments:
	pdb_run.py
> /Users/dhellmann/Dropbox/PyMOTW/Python3/pymotw-3/source/pdb/pdb_run.py(7)<module>()
-> import sys


It looks like the issue is in the pdb main loop. Under 2.7 the restart logic has:

except Restart:
    print "Restarting", mainpyfile, "with arguments:"
    print "\t" + " ".join(sys.argv[1:])


but under 3.5 that was changed to:

except Restart:
    print("Restarting", mainpyfile, "with arguments:")
    print("\t" + " ".join(args))


The do_run() method has already reset sys.argv before throwing Restart, so to print the correct arguments sys.argv[1:] should be used.
msg257786 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2016-01-08 23:44
I should also mention that I haven't tested early versions of 3.x to see where exactly the regression was introduced.
msg376164 - (view) Author: Irit Katriel (iritkatriel) * (Python triager) Date: 2020-08-31 19:01
The regression was introduced here: https://github.com/python/cpython/commit/e023091815e4946e42c1af102be1f258b2f47cb8

in main() it prints " ".join(sys.argv[1:]) instead of " ".join(args).  

In do_run (line 1029) sys.argv gets updated with the arg for that particular "run" command:   sys.argv = shlex.split(arg)

The quickest fix would be to change main back to print sys.argv rather than arg. But I'm a little uneasy with a program modifying sys.argv (I wouldn't do it). So I'm wondering if that should be changed. What do you think?
msg380404 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-11-05 11:09
I'm also uneasy about the sys.argv mangling.

It seem to me that it would be safer, and more explicit, to pass the desired arguments in the Restart exception instance.
msg380405 - (view) Author: Irit Katriel (iritkatriel) * (Python triager) Date: 2020-11-05 11:21
I like the idea of adding it to the Restart exception. Should we do this refactor in the same PR as fixing the regression or keep them separate?
msg380407 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2020-11-05 11:54
Since it's a different implementation approach, I'd prefer a separate PR.

Whether we merge the existing one depends on whether we'd like to backport a fix for this to 3.9 and 3.8.
msg389994 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-04-01 15:26
New changeset 652bfdee9495dca241d48278742fe035b7a82bdb by Irit Katriel in branch 'master':
bpo-26053: Fix args echoed by pdb run command (#22033)
https://github.com/python/cpython/commit/652bfdee9495dca241d48278742fe035b7a82bdb
msg390006 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-01 19:06
New changeset bd4ab8e73906a4f12d5353f567228b7c7497baf7 by Irit Katriel in branch 'master':
bpo-26053: Fix test_pdb.test_issue26053() (GH-25139)
https://github.com/python/cpython/commit/bd4ab8e73906a4f12d5353f567228b7c7497baf7
msg390026 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-04-02 01:40
Do you need my help here?
msg390040 - (view) Author: Irit Katriel (iritkatriel) * (Python triager) Date: 2021-04-02 05:45
It’s fixed now. The tests failed when we merged this old PR. I guess they passed a few months ago but something changed in the meantime.
I don’t know if there’s something to do in the CI to prevent this (expire the test run after a while?)

If we want to backport then we need both PRs.
msg390043 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-02 08:23
> If we want to backport then we need both PRs.

Commit 652bfdee9495dca241d48278742fe035b7a82bdb is a bugfix and this issue is marked as Python 3.8-3.10, so yeah, a backport is worth it.

You can create a PR for Python 3.9 combining the two commits. I like to use "git cherry-pick -x <sha1>" manually for that. And then, use the label to backport this PR to Python 3.8.
msg390051 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-04-02 11:16
New changeset 7ad56e254519047aeb9c669b9ea2f2bf0acfd401 by Irit Katriel in branch '3.9':
[3.9] bpo-26053: Fix args echoed by pdb run command  (GH-25149)
https://github.com/python/cpython/commit/7ad56e254519047aeb9c669b9ea2f2bf0acfd401
msg390052 - (view) Author: miss-islington (miss-islington) Date: 2021-04-02 11:33
New changeset 2049bb2517c08b0d9eaaa4dd624afa5d60e8b5a8 by Miss Islington (bot) in branch '3.8':
[3.9] bpo-26053: Fix args echoed by pdb run command  (GH-25149)
https://github.com/python/cpython/commit/2049bb2517c08b0d9eaaa4dd624afa5d60e8b5a8
msg390053 - (view) Author: Irit Katriel (iritkatriel) * (Python triager) Date: 2021-04-02 11:39
Thanks, Victor.

I created a workflow issue for the CI question:
https://github.com/python/core-workflow/issues/393
History
Date User Action Args
2021-04-02 11:39:55iritkatrielsetstatus: open -> closed
resolution: fixed
messages: + msg390053

stage: patch review -> resolved
2021-04-02 11:33:38miss-islingtonsetmessages: + msg390052
2021-04-02 11:17:09miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23897
2021-04-02 11:16:59vstinnersetmessages: + msg390051
2021-04-02 10:40:44iritkatrielsetpull_requests: + pull_request23896
2021-04-02 08:23:31vstinnersetmessages: + msg390043
2021-04-02 05:45:26iritkatrielsetmessages: + msg390040
2021-04-02 01:40:18gvanrossumsetmessages: + msg390026
2021-04-01 19:06:10vstinnersetnosy: + vstinner
messages: + msg390006
2021-04-01 16:01:52iritkatrielsetpull_requests: + pull_request23886
2021-04-01 15:26:11gvanrossumsetnosy: + gvanrossum
messages: + msg389994
2020-11-05 11:54:02taleinatsetmessages: + msg380407
2020-11-05 11:21:26iritkatrielsetmessages: + msg380405
2020-11-05 11:09:27taleinatsetnosy: + taleinat
messages: + msg380404
2020-11-05 10:07:54iritkatrielsetmessages: - msg377666
2020-09-29 12:21:59iritkatrielsetmessages: + msg377666
2020-09-19 19:02:22georg.brandlsetnosy: - georg.brandl
2020-09-01 16:23:02vstinnersetnosy: - vstinner
2020-08-31 19:43:19iritkatrielsetcomponents: + Library (Lib)
versions: + Python 3.8, Python 3.9, Python 3.10, - Python 3.5, Python 3.6
2020-08-31 19:40:02iritkatrielsetkeywords: + patch
stage: patch review
pull_requests: + pull_request21131
2020-08-31 19:01:35iritkatrielsetnosy: + iritkatriel
messages: + msg376164
2016-01-16 10:24:57xdegayesetnosy: + xdegaye
2016-01-09 07:42:56serhiy.storchakasetnosy: + georg.brandl
2016-01-09 02:10:57vstinnersetnosy: + vstinner
2016-01-08 23:44:27doughellmannsetmessages: + msg257786
2016-01-08 23:43:41doughellmanncreate