Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-103143: Polish pdb help messages and doc strings #103144

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

Merged
merged 7 commits into from
Apr 11, 2023

Conversation

gaogaotiantian
Copy link
Member

@gaogaotiantian gaogaotiantian commented Mar 31, 2023

  • Made all the command part of the docstring match the official documentation
  • Always have a space between the command and the description in docstring
  • Added a helper function to format the help message

Before:

(Pdb) h a
a(rgs)
        Print the argument list of the current function.
(Pdb) h commands
commands [bpnumber]
        (com) ...
        (com) end
        (Pdb)
        ...
(Pdb) h interact
interact

        Start an interactive interpreter whose global namespace
        contains all the (global and local) names found in the current scope.

After

(Pdb) h a
      Usage: a(rgs)
      
      Print the argument list of the current function.
(Pdb) h commands
      Usage: (Pdb) commands [bpnumber]
             (com) ...
             (com) end
             (Pdb)
             ...
(Pdb) h interact
      Usage: interact
      
      Start an interactive interpreter whose global namespace
      contains all the (global and local) names found in the current scope.

Automerge-Triggered-By: GH:brandtbucher

@arhadthedev arhadthedev added the stdlib Python modules in the Lib dir label Mar 31, 2023
Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

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

A few nitpicks. Let me know what you think:

@@ -945,7 +951,8 @@ def do_ignore(self, arg):
complete_ignore = _complete_bpnumber

def do_clear(self, arg):
"""cl(ear) filename:lineno\ncl(ear) [bpnumber [bpnumber...]]
"""cl(ear) [filename:lineno | bpnumber ...]
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a more accurate description, right?

Suggested change
"""cl(ear) [filename:lineno | bpnumber ...]
"""cl(ear) [filename:lineno] [bpnumber ...]

Copy link
Member Author

Choose a reason for hiding this comment

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

clear command takes either a filename:lineno or a list of bpnumber. [filename:lineno] [bpnumber ...] suggests that they could both exist, which won't work.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I missed the early return on 990!

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, now that I took at look at the code, this is not what I would write. I'd use three mutual exclusive if cases instead of early returns.

Lib/pdb.py Outdated
Comment on lines 590 to 592
(com) ...
(com) end
(Pdb)
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why the indent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to align better in docstring. This is what the users see when they use this command.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I sort of prefer it as is. It doesn't affect how pdb's help is formatted, but it does break help formatting for this function itself:

help(pdb.Pdb.do_commands) before:

Help on function do_commands in module pdb:

do_commands(self, arg)
    commands [bpnumber]
    (com) ...
    (com) end
    (Pdb)

    Specify a list of commands for breakpoint number bpnumber.

After:

Help on function do_commands in module pdb:

do_commands(self, arg)
    (Pdb) commands [bpnumber]
       (com) ...
       (com) end
       (Pdb)

    Specify a list of commands for breakpoint number bpnumber.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, inspect.cleandocs cleans up the common indent. Ok then, I guess we should not introduce the indent.

@brandtbucher brandtbucher self-assigned this Apr 11, 2023
@brandtbucher
Copy link
Member

Thanks for the PR!

@gaogaotiantian
Copy link
Member Author

Thank you for your time to review!

@brandtbucher
Copy link
Member

No problem.

Also, I'm surprised we don't have any tests for the help formatting. Maybe it's worth adding a couple of doctests to test_pdb to make sure we don't regress on this?

@gaogaotiantian
Copy link
Member Author

What do you have in your mind to check against? It's not like there's a "correct" format for docs. We can make sure that all commands have help message. The format is rather arbitrary right?

@miss-islington
Copy link
Contributor

Status check is done, and it's a success ✅.

@miss-islington miss-islington merged commit 2f41a00 into python:main Apr 11, 2023
@gaogaotiantian gaogaotiantian deleted the pdb-help-improve branch April 12, 2023 00:19
aisk pushed a commit to aisk/cpython that referenced this pull request Apr 18, 2023
…03144)

* Made all the command part of the docstring match the official documentation
* Always have a space between the command and the description in docstring
* Added a helper function to format the help message

Before:

```
(Pdb) h a
a(rgs)
        Print the argument list of the current function.
(Pdb) h commands
commands [bpnumber]
        (com) ...
        (com) end
        (Pdb)
        ...
(Pdb) h interact
interact

        Start an interactive interpreter whose global namespace
        contains all the (global and local) names found in the current scope.
```

After
```
(Pdb) h a
      Usage: a(rgs)
      
      Print the argument list of the current function.
(Pdb) h commands
      Usage: (Pdb) commands [bpnumber]
             (com) ...
             (com) end
             (Pdb)
             ...
(Pdb) h interact
      Usage: interact
      
      Start an interactive interpreter whose global namespace
      contains all the (global and local) names found in the current scope.
```

Automerge-Triggered-By: GH:brandtbucher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants