gh-104301: Allow leading whitespace in disambiguated pdb statements (#104342)

This commit is contained in:
James Gerity 2023-05-11 13:12:02 -04:00 committed by GitHub
parent 27419a71b5
commit 0449ffe3a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 12 deletions

View file

@ -602,9 +602,17 @@ can be overridden by the local file.
Execute the (one-line) *statement* in the context of the current stack frame. Execute the (one-line) *statement* in the context of the current stack frame.
The exclamation point can be omitted unless the first word of the statement The exclamation point can be omitted unless the first word of the statement
resembles a debugger command. To set a global variable, you can prefix the resembles a debugger command, e.g.:
assignment command with a :keyword:`global` statement on the same line,
e.g.:: .. code-block:: none
(Pdb) ! n=42
(Pdb)
To set a global variable, you can prefix the assignment command with a
:keyword:`global` statement on the same line, e.g.:
.. code-block:: none
(Pdb) global list_options; list_options = ['-l'] (Pdb) global list_options; list_options = ['-l']
(Pdb) (Pdb)

View file

@ -440,7 +440,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
self.message(repr(obj)) self.message(repr(obj))
def default(self, line): def default(self, line):
if line[:1] == '!': line = line[1:] if line[:1] == '!': line = line[1:].strip()
locals = self.curframe_locals locals = self.curframe_locals
globals = self.curframe.f_globals globals = self.curframe.f_globals
try: try:
@ -1642,9 +1642,12 @@ class Pdb(bdb.Bdb, cmd.Cmd):
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, e.g.:
assign to a global variable you must always prefix the command (Pdb) ! n=42
with a 'global' command, e.g.: (Pdb)
To assign to a global variable you must always prefix the command with
a 'global' command, e.g.:
(Pdb) global list_options; list_options = ['-l'] (Pdb) global list_options; list_options = ['-l']
(Pdb) (Pdb)
""" """

View file

@ -5283,11 +5283,14 @@ topics = {'assert': 'The "assert" statement\n'
'current\n' 'current\n'
' stack frame. The exclamation point can be omitted unless the ' ' stack frame. The exclamation point can be omitted unless the '
'first\n' 'first\n'
' word of the statement resembles a debugger command. To set ' ' word of the statement resembles a debugger command, e.g.:'
'a\n' '\n'
' global variable, you can prefix the assignment command with ' ' (Pdb) ! n=42\n'
'a\n' ' (Pdb)\n'
' "global" statement on the same line, e.g.:\n' '\n'
' To set a global variable, you can prefix the assignment command '
' with \n'
' a "global" statement on the same line, e.g.:\n'
'\n' '\n'
" (Pdb) global list_options; list_options = ['-l']\n" " (Pdb) global list_options; list_options = ['-l']\n"
' (Pdb)\n' ' (Pdb)\n'

View file

@ -1798,6 +1798,29 @@ def test_pdb_issue_gh_101517():
(Pdb) continue (Pdb) continue
""" """
def test_pdb_ambiguous_statements():
"""See GH-104301
Make sure that ambiguous statements prefixed by '!' are properly disambiguated
>>> with PdbTestInput([
... '! n = 42', # disambiguated statement: reassign the name n
... 'n', # advance the debugger into the print()
... 'continue'
... ]):
... n = -1
... import pdb; pdb.Pdb(nosigint=True, readrc=False).set_trace()
... print(f"The value of n is {n}")
> <doctest test.test_pdb.test_pdb_ambiguous_statements[0]>(8)<module>()
-> print(f"The value of n is {n}")
(Pdb) ! n = 42
(Pdb) n
The value of n is 42
> <doctest test.test_pdb.test_pdb_ambiguous_statements[0]>(1)<module>()
-> with PdbTestInput([
(Pdb) continue
"""
@support.requires_subprocess() @support.requires_subprocess()
class PdbTestCase(unittest.TestCase): class PdbTestCase(unittest.TestCase):

View file

@ -0,0 +1 @@
Allow leading whitespace in disambiguated statements in :mod:`pdb`.