mirror of
https://github.com/python/cpython.git
synced 2025-11-11 14:44:57 +00:00
gh-103143: Polish pdb help messages and doc strings (GH-103144)
* 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
This commit is contained in:
parent
96663875b2
commit
2f41a009b7
3 changed files with 62 additions and 10 deletions
|
|
@ -315,14 +315,14 @@ can be overridden by the local file.
|
||||||
With a space separated list of breakpoint numbers, clear those breakpoints.
|
With a space separated list of breakpoint numbers, clear those breakpoints.
|
||||||
Without argument, clear all breaks (but first ask confirmation).
|
Without argument, clear all breaks (but first ask confirmation).
|
||||||
|
|
||||||
.. pdbcommand:: disable [bpnumber ...]
|
.. pdbcommand:: disable bpnumber [bpnumber ...]
|
||||||
|
|
||||||
Disable the breakpoints given as a space separated list of breakpoint
|
Disable the breakpoints given as a space separated list of breakpoint
|
||||||
numbers. Disabling a breakpoint means it cannot cause the program to stop
|
numbers. Disabling a breakpoint means it cannot cause the program to stop
|
||||||
execution, but unlike clearing a breakpoint, it remains in the list of
|
execution, but unlike clearing a breakpoint, it remains in the list of
|
||||||
breakpoints and can be (re-)enabled.
|
breakpoints and can be (re-)enabled.
|
||||||
|
|
||||||
.. pdbcommand:: enable [bpnumber ...]
|
.. pdbcommand:: enable bpnumber [bpnumber ...]
|
||||||
|
|
||||||
Enable the breakpoints specified.
|
Enable the breakpoints specified.
|
||||||
|
|
||||||
|
|
|
||||||
65
Lib/pdb.py
65
Lib/pdb.py
|
|
@ -586,7 +586,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
# Return true to exit from the command loop
|
# Return true to exit from the command loop
|
||||||
|
|
||||||
def do_commands(self, arg):
|
def do_commands(self, arg):
|
||||||
"""commands [bpnumber]
|
"""(Pdb) commands [bpnumber]
|
||||||
(com) ...
|
(com) ...
|
||||||
(com) end
|
(com) end
|
||||||
(Pdb)
|
(Pdb)
|
||||||
|
|
@ -672,6 +672,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_break(self, arg, temporary = 0):
|
def do_break(self, arg, temporary = 0):
|
||||||
"""b(reak) [ ([filename:]lineno | function) [, condition] ]
|
"""b(reak) [ ([filename:]lineno | function) [, condition] ]
|
||||||
|
|
||||||
Without argument, list all breaks.
|
Without argument, list all breaks.
|
||||||
|
|
||||||
With a line number argument, set a break at this line in the
|
With a line number argument, set a break at this line in the
|
||||||
|
|
@ -780,6 +781,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_tbreak(self, arg):
|
def do_tbreak(self, arg):
|
||||||
"""tbreak [ ([filename:]lineno | function) [, condition] ]
|
"""tbreak [ ([filename:]lineno | function) [, condition] ]
|
||||||
|
|
||||||
Same arguments as break, but sets a temporary breakpoint: it
|
Same arguments as break, but sets a temporary breakpoint: it
|
||||||
is automatically deleted when first hit.
|
is automatically deleted when first hit.
|
||||||
"""
|
"""
|
||||||
|
|
@ -844,6 +846,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_enable(self, arg):
|
def do_enable(self, arg):
|
||||||
"""enable bpnumber [bpnumber ...]
|
"""enable bpnumber [bpnumber ...]
|
||||||
|
|
||||||
Enables the breakpoints given as a space separated list of
|
Enables the breakpoints given as a space separated list of
|
||||||
breakpoint numbers.
|
breakpoint numbers.
|
||||||
"""
|
"""
|
||||||
|
|
@ -861,6 +864,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_disable(self, arg):
|
def do_disable(self, arg):
|
||||||
"""disable bpnumber [bpnumber ...]
|
"""disable bpnumber [bpnumber ...]
|
||||||
|
|
||||||
Disables the breakpoints given as a space separated list of
|
Disables the breakpoints given as a space separated list of
|
||||||
breakpoint numbers. Disabling a breakpoint means it cannot
|
breakpoint numbers. Disabling a breakpoint means it cannot
|
||||||
cause the program to stop execution, but unlike clearing a
|
cause the program to stop execution, but unlike clearing a
|
||||||
|
|
@ -881,6 +885,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_condition(self, arg):
|
def do_condition(self, arg):
|
||||||
"""condition bpnumber [condition]
|
"""condition bpnumber [condition]
|
||||||
|
|
||||||
Set a new condition for the breakpoint, an expression which
|
Set a new condition for the breakpoint, an expression which
|
||||||
must evaluate to true before the breakpoint is honored. If
|
must evaluate to true before the breakpoint is honored. If
|
||||||
condition is absent, any existing condition is removed; i.e.,
|
condition is absent, any existing condition is removed; i.e.,
|
||||||
|
|
@ -911,6 +916,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_ignore(self, arg):
|
def do_ignore(self, arg):
|
||||||
"""ignore bpnumber [count]
|
"""ignore bpnumber [count]
|
||||||
|
|
||||||
Set the ignore count for the given breakpoint number. If
|
Set the ignore count for the given breakpoint number. If
|
||||||
count is omitted, the ignore count is set to 0. A breakpoint
|
count is omitted, the ignore count is set to 0. A breakpoint
|
||||||
becomes active when the ignore count is zero. When non-zero,
|
becomes active when the ignore count is zero. When non-zero,
|
||||||
|
|
@ -945,7 +951,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
complete_ignore = _complete_bpnumber
|
complete_ignore = _complete_bpnumber
|
||||||
|
|
||||||
def do_clear(self, arg):
|
def do_clear(self, arg):
|
||||||
"""cl(ear) filename:lineno\ncl(ear) [bpnumber [bpnumber...]]
|
"""cl(ear) [filename:lineno | bpnumber ...]
|
||||||
|
|
||||||
With a space separated list of breakpoint numbers, clear
|
With a space separated list of breakpoint numbers, clear
|
||||||
those breakpoints. Without argument, clear all breaks (but
|
those breakpoints. Without argument, clear all breaks (but
|
||||||
first ask confirmation). With a filename:lineno argument,
|
first ask confirmation). With a filename:lineno argument,
|
||||||
|
|
@ -997,6 +1004,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_where(self, arg):
|
def do_where(self, arg):
|
||||||
"""w(here)
|
"""w(here)
|
||||||
|
|
||||||
Print a stack trace, with the most recent frame at the bottom.
|
Print a stack trace, with the most recent frame at the bottom.
|
||||||
An arrow indicates the "current frame", which determines the
|
An arrow indicates the "current frame", which determines the
|
||||||
context of most commands. 'bt' is an alias for this command.
|
context of most commands. 'bt' is an alias for this command.
|
||||||
|
|
@ -1015,6 +1023,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_up(self, arg):
|
def do_up(self, arg):
|
||||||
"""u(p) [count]
|
"""u(p) [count]
|
||||||
|
|
||||||
Move the current frame count (default one) levels up in the
|
Move the current frame count (default one) levels up in the
|
||||||
stack trace (to an older frame).
|
stack trace (to an older frame).
|
||||||
"""
|
"""
|
||||||
|
|
@ -1035,6 +1044,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_down(self, arg):
|
def do_down(self, arg):
|
||||||
"""d(own) [count]
|
"""d(own) [count]
|
||||||
|
|
||||||
Move the current frame count (default one) levels down in the
|
Move the current frame count (default one) levels down in the
|
||||||
stack trace (to a newer frame).
|
stack trace (to a newer frame).
|
||||||
"""
|
"""
|
||||||
|
|
@ -1055,6 +1065,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_until(self, arg):
|
def do_until(self, arg):
|
||||||
"""unt(il) [lineno]
|
"""unt(il) [lineno]
|
||||||
|
|
||||||
Without argument, continue execution until the line with a
|
Without argument, continue execution until the line with a
|
||||||
number greater than the current one is reached. With a line
|
number greater than the current one is reached. With a line
|
||||||
number, continue execution until a line with a number greater
|
number, continue execution until a line with a number greater
|
||||||
|
|
@ -1079,6 +1090,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_step(self, arg):
|
def do_step(self, arg):
|
||||||
"""s(tep)
|
"""s(tep)
|
||||||
|
|
||||||
Execute the current line, stop at the first possible occasion
|
Execute the current line, stop at the first possible occasion
|
||||||
(either in a function that is called or in the current
|
(either in a function that is called or in the current
|
||||||
function).
|
function).
|
||||||
|
|
@ -1089,6 +1101,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_next(self, arg):
|
def do_next(self, arg):
|
||||||
"""n(ext)
|
"""n(ext)
|
||||||
|
|
||||||
Continue execution until the next line in the current function
|
Continue execution until the next line in the current function
|
||||||
is reached or it returns.
|
is reached or it returns.
|
||||||
"""
|
"""
|
||||||
|
|
@ -1098,6 +1111,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_run(self, arg):
|
def do_run(self, arg):
|
||||||
"""run [args...]
|
"""run [args...]
|
||||||
|
|
||||||
Restart the debugged python program. If a string is supplied
|
Restart the debugged python program. If a string is supplied
|
||||||
it is split with "shlex", and the result is used as the new
|
it is split with "shlex", and the result is used as the new
|
||||||
sys.argv. History, breakpoints, actions and debugger options
|
sys.argv. History, breakpoints, actions and debugger options
|
||||||
|
|
@ -1119,6 +1133,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_return(self, arg):
|
def do_return(self, arg):
|
||||||
"""r(eturn)
|
"""r(eturn)
|
||||||
|
|
||||||
Continue execution until the current function returns.
|
Continue execution until the current function returns.
|
||||||
"""
|
"""
|
||||||
self.set_return(self.curframe)
|
self.set_return(self.curframe)
|
||||||
|
|
@ -1127,6 +1142,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_continue(self, arg):
|
def do_continue(self, arg):
|
||||||
"""c(ont(inue))
|
"""c(ont(inue))
|
||||||
|
|
||||||
Continue execution, only stop when a breakpoint is encountered.
|
Continue execution, only stop when a breakpoint is encountered.
|
||||||
"""
|
"""
|
||||||
if not self.nosigint:
|
if not self.nosigint:
|
||||||
|
|
@ -1145,6 +1161,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_jump(self, arg):
|
def do_jump(self, arg):
|
||||||
"""j(ump) lineno
|
"""j(ump) lineno
|
||||||
|
|
||||||
Set the next line that will be executed. Only available in
|
Set the next line that will be executed. Only available in
|
||||||
the bottom-most frame. This lets you jump back and execute
|
the bottom-most frame. This lets you jump back and execute
|
||||||
code again, or jump forward to skip code that you don't want
|
code again, or jump forward to skip code that you don't want
|
||||||
|
|
@ -1174,6 +1191,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_debug(self, arg):
|
def do_debug(self, arg):
|
||||||
"""debug code
|
"""debug code
|
||||||
|
|
||||||
Enter a recursive debugger that steps through the code
|
Enter a recursive debugger that steps through the code
|
||||||
argument (which is an arbitrary expression or statement to be
|
argument (which is an arbitrary expression or statement to be
|
||||||
executed in the current environment).
|
executed in the current environment).
|
||||||
|
|
@ -1195,7 +1213,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
complete_debug = _complete_expression
|
complete_debug = _complete_expression
|
||||||
|
|
||||||
def do_quit(self, arg):
|
def do_quit(self, arg):
|
||||||
"""q(uit)\nexit
|
"""q(uit) | exit
|
||||||
|
|
||||||
Quit from the debugger. The program being executed is aborted.
|
Quit from the debugger. The program being executed is aborted.
|
||||||
"""
|
"""
|
||||||
self._user_requested_quit = True
|
self._user_requested_quit = True
|
||||||
|
|
@ -1207,6 +1226,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_EOF(self, arg):
|
def do_EOF(self, arg):
|
||||||
"""EOF
|
"""EOF
|
||||||
|
|
||||||
Handles the receipt of EOF as a command.
|
Handles the receipt of EOF as a command.
|
||||||
"""
|
"""
|
||||||
self.message('')
|
self.message('')
|
||||||
|
|
@ -1216,6 +1236,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_args(self, arg):
|
def do_args(self, arg):
|
||||||
"""a(rgs)
|
"""a(rgs)
|
||||||
|
|
||||||
Print the argument list of the current function.
|
Print the argument list of the current function.
|
||||||
"""
|
"""
|
||||||
co = self.curframe.f_code
|
co = self.curframe.f_code
|
||||||
|
|
@ -1233,6 +1254,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_retval(self, arg):
|
def do_retval(self, arg):
|
||||||
"""retval
|
"""retval
|
||||||
|
|
||||||
Print the return value for the last return of a function.
|
Print the return value for the last return of a function.
|
||||||
"""
|
"""
|
||||||
if '__return__' in self.curframe_locals:
|
if '__return__' in self.curframe_locals:
|
||||||
|
|
@ -1273,12 +1295,14 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_p(self, arg):
|
def do_p(self, arg):
|
||||||
"""p expression
|
"""p expression
|
||||||
|
|
||||||
Print the value of the expression.
|
Print the value of the expression.
|
||||||
"""
|
"""
|
||||||
self._msg_val_func(arg, repr)
|
self._msg_val_func(arg, repr)
|
||||||
|
|
||||||
def do_pp(self, arg):
|
def do_pp(self, arg):
|
||||||
"""pp expression
|
"""pp expression
|
||||||
|
|
||||||
Pretty-print the value of the expression.
|
Pretty-print the value of the expression.
|
||||||
"""
|
"""
|
||||||
self._msg_val_func(arg, pprint.pformat)
|
self._msg_val_func(arg, pprint.pformat)
|
||||||
|
|
@ -1345,7 +1369,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
do_l = do_list
|
do_l = do_list
|
||||||
|
|
||||||
def do_longlist(self, arg):
|
def do_longlist(self, arg):
|
||||||
"""longlist | ll
|
"""ll | longlist
|
||||||
|
|
||||||
List the whole source code for the current function or frame.
|
List the whole source code for the current function or frame.
|
||||||
"""
|
"""
|
||||||
filename = self.curframe.f_code.co_filename
|
filename = self.curframe.f_code.co_filename
|
||||||
|
|
@ -1360,6 +1385,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_source(self, arg):
|
def do_source(self, arg):
|
||||||
"""source expression
|
"""source expression
|
||||||
|
|
||||||
Try to get source code for the given object and display it.
|
Try to get source code for the given object and display it.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -1397,7 +1423,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
self.message(s + '\t' + line.rstrip())
|
self.message(s + '\t' + line.rstrip())
|
||||||
|
|
||||||
def do_whatis(self, arg):
|
def do_whatis(self, arg):
|
||||||
"""whatis arg
|
"""whatis expression
|
||||||
|
|
||||||
Print the type of the argument.
|
Print the type of the argument.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
|
@ -1485,7 +1512,8 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
code.interact("*interactive*", local=ns)
|
code.interact("*interactive*", local=ns)
|
||||||
|
|
||||||
def do_alias(self, arg):
|
def do_alias(self, arg):
|
||||||
"""alias [name [command [parameter parameter ...] ]]
|
"""alias [name [command]]
|
||||||
|
|
||||||
Create an alias called 'name' that executes 'command'. The
|
Create an alias called 'name' that executes 'command'. The
|
||||||
command must *not* be enclosed in quotes. Replaceable
|
command must *not* be enclosed in quotes. Replaceable
|
||||||
parameters can be indicated by %1, %2, and so on, while %* is
|
parameters can be indicated by %1, %2, and so on, while %* is
|
||||||
|
|
@ -1521,6 +1549,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_unalias(self, arg):
|
def do_unalias(self, arg):
|
||||||
"""unalias name
|
"""unalias name
|
||||||
|
|
||||||
Delete the specified alias.
|
Delete the specified alias.
|
||||||
"""
|
"""
|
||||||
args = arg.split()
|
args = arg.split()
|
||||||
|
|
@ -1563,6 +1592,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
|
|
||||||
def do_help(self, arg):
|
def do_help(self, arg):
|
||||||
"""h(elp)
|
"""h(elp)
|
||||||
|
|
||||||
Without argument, print the list of available commands.
|
Without argument, print the list of available commands.
|
||||||
With a command name as argument, print help about that command.
|
With a command name as argument, print help about that command.
|
||||||
"help pdb" shows the full pdb documentation.
|
"help pdb" shows the full pdb documentation.
|
||||||
|
|
@ -1586,12 +1616,13 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
if command.__doc__ is None:
|
if command.__doc__ is None:
|
||||||
self.error('No help for %r; __doc__ string missing' % arg)
|
self.error('No help for %r; __doc__ string missing' % arg)
|
||||||
return
|
return
|
||||||
self.message(command.__doc__.rstrip())
|
self.message(self._help_message_from_doc(command.__doc__))
|
||||||
|
|
||||||
do_h = do_help
|
do_h = do_help
|
||||||
|
|
||||||
def help_exec(self):
|
def help_exec(self):
|
||||||
"""(!) statement
|
"""(!) statement
|
||||||
|
|
||||||
Execute the (one-line) statement in the context of the current
|
Execute the (one-line) statement in the context of the current
|
||||||
stack frame. The exclamation point can be omitted unless the
|
stack frame. The exclamation point can be omitted unless the
|
||||||
first word of the statement resembles a debugger command. To
|
first word of the statement resembles a debugger command. To
|
||||||
|
|
@ -1672,6 +1703,26 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
lineno = max(1, lineno)
|
lineno = max(1, lineno)
|
||||||
return lines, lineno
|
return lines, lineno
|
||||||
|
|
||||||
|
def _help_message_from_doc(self, doc):
|
||||||
|
lines = [line.strip() for line in doc.rstrip().splitlines()]
|
||||||
|
if not lines:
|
||||||
|
return "No help message found."
|
||||||
|
if "" in lines:
|
||||||
|
usage_end = lines.index("")
|
||||||
|
else:
|
||||||
|
usage_end = 1
|
||||||
|
formatted = []
|
||||||
|
indent = " " * len(self.prompt)
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if i == 0:
|
||||||
|
prefix = "Usage: "
|
||||||
|
elif i < usage_end:
|
||||||
|
prefix = " "
|
||||||
|
else:
|
||||||
|
prefix = ""
|
||||||
|
formatted.append(indent + prefix + line)
|
||||||
|
return "\n".join(formatted)
|
||||||
|
|
||||||
# Collect all command help into docstring, if not run with -OO
|
# Collect all command help into docstring, if not run with -OO
|
||||||
|
|
||||||
if __doc__ is not None:
|
if __doc__ is not None:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Polish the help messages and docstrings of :mod:`pdb`.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue