-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
gh-109164: Replace getopt with argparse in pdb
#109165
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
Changes from 1 commit
a9d0109
6c5bb11
d51219c
e417507
cdf3570
2defa6b
f14bc09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2079,11 +2079,13 @@ def main(): | |
|
|
||
| parser = argparse.ArgumentParser(prog="pdb", | ||
| description=_usage, | ||
| formatter_class=argparse.RawDescriptionHelpFormatter) | ||
| formatter_class=argparse.RawDescriptionHelpFormatter, | ||
| allow_abbrev=False) | ||
|
|
||
| parser.add_argument('-c', '--command', action='append', default=[]) | ||
| parser.add_argument('-m', action='store_true') | ||
| parser.add_argument('pyfile', nargs=1) | ||
| parser.add_argument('-c', '--command', action='append', default=[], metavar='command') | ||
| grp = parser.add_mutually_exclusive_group(required=True) | ||
| grp.add_argument('-m', metavar='module') | ||
| grp.add_argument('pyfile', nargs='?') | ||
| parser.add_argument('args', nargs="*") | ||
|
|
||
| if len(sys.argv) == 1: | ||
AA-Turner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -2092,12 +2094,16 @@ def main(): | |
|
|
||
| opts = parser.parse_args() | ||
|
|
||
| cls = _ModuleTarget if opts.m else _ScriptTarget | ||
| target = cls(opts.pyfile[0]) | ||
| if opts.m: | ||
| file = opts.m | ||
| target = _ModuleTarget(file) | ||
| else: | ||
| file = opts.pyfile | ||
| target = _ScriptTarget(opts.pyfile[0]) | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a larger refactor, the current state reflects what's currently present.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, that's why I'm asking for :-)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic is pretty similar right? Just a slightly different implementation. I don't think this is too much if this is preferred.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just disturbed by calling "module" a "file".
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, feel free to ignore my comment about this code. |
||
| target.check() | ||
|
|
||
| sys.argv[:] = opts.pyfile + opts.args # Hide "pdb.py" and pdb options from argument list | ||
| sys.argv[:] = [file] + opts.args # Hide "pdb.py" and pdb options from argument list | ||
|
|
||
| # Note on saving/restoring sys.argv: it's a good idea when sys.argv was | ||
| # modified by the script being debugged. It's a bad idea when it was | ||
|
|
||
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.
It's surprising that -c looks like python -c option, but different. Would you mind to add a help message to explain that there are pdb commands? And that they have the same format than
.pdbrcconfiguration files?I suggest to add
dest='commands', since it's non-obvious fromcommandname that's a list.