-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-125115: Pass unknown pdb command line args to script instead of fail #125424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Lib/pdb.py
Outdated
invalid_args = [] | ||
for arg in args: | ||
if not arg.startswith('-'): | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the logic here? Why are we breaking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A pdb CLI usage could be python -m pdb script.py --bar
or python -m pdb --bar script.py
.
The unknown args would be ['script.py', '--bar']
and [--bar', 'script.py']
respectively. Notice that in the first case, the user is trying to pass --bar
to script.py
, but in the latter, they try to pass --bar
to pdb
. This logic is to differentiate this. As long as we got something that does not start with -
, we consider that as the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing something here, for the module case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing something here, for the module case.
And a test for this case..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out dealing with modules is not super trivial. I added some comments in the parsing code and hopefully that's helpful. We can "change the rule" and require users to use --
to resolve all ambiguities, but I think it would be a better experience if we can be a bit smarter.
An existing test already covers the case where --spam -m module
should fail, I added a new test for -m calendar --type text
which works after the change.
Lib/pdb.py
Outdated
for arg in args: | ||
if not arg.startswith('-'): | ||
break | ||
invalid_args.append(arg) | ||
|
||
if invalid_args: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for arg in args: | |
if not arg.startswith('-'): | |
break | |
invalid_args.append(arg) | |
if invalid_args: | |
if any(itertools.takewhile(lambda a: a.startswith('-'), args)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a better expression. Just one question - is it okay to import itertools
in pdb
? We do already use plenty of internal libraries, but there were concerns about using pdb
to debug stdlib when they are not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we need to full list of invalid arguments to report to keep the old behavior I think. So we need to turn this takewhiel
to a list and check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pdb imports traceback which imports itertools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if the stdlib is broken you probably need to debug it on a previous version of python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I used takewhile
for invalid arguments now, but we do need the full list so I converted it to a list as well.
Co-authored-by: Irit Katriel <[email protected]>
Thanks @gaogaotiantian for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
… of fail (pythonGH-125424) (cherry picked from commit 9c2bb7d) Co-authored-by: Tian Gao <[email protected]> Co-authored-by: Irit Katriel <[email protected]>
GH-125547 is a backport of this pull request to the 3.13 branch. |
…d of fail (GH-125424) (#125547) gh-125115: Pass unknown pdb command line args to script instead of fail (GH-125424) (cherry picked from commit 9c2bb7d) Co-authored-by: Tian Gao <[email protected]> Co-authored-by: Irit Katriel <[email protected]>
… of fail (python#125424) Co-authored-by: Irit Katriel <[email protected]>
Moving to
argparse
created a bug where an argument starting with-
to the script being debugged will be parsed, which frustratedargparse
. We should just parse known args and pass the rest to the script.