pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/109165/commits/d51219ce7a84241fa654a9f518f7dfb79a24340c

rimer-primitives-ef1311e26457f1ec.css" /> gh-109164: Replace `getopt` with `argparse` in pdb by gaogaotiantian · Pull Request #109165 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
gaogaotiantian and AA-Turner authored Sep 10, 2023
commit d51219ce7a84241fa654a9f518f7dfb79a24340c
20 changes: 13 additions & 7 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

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 .pdbrc configuration files?

I suggest to add dest='commands', since it's non-obvious from command name that's a list.

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:
Expand All @@ -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])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer:

if opts.module:
    args = [opts.module]
    ...
else:
    args = [opts.pyfile]
    ...

args.extend(opts.ags)

...

sys.argv = args  # Hide "pdb.py" and pdb options from argument list

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's why I'm asking for :-)

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just disturbed by calling "module" a "file".

Copy link
Member

Choose a reason for hiding this comment

The 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
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy