diff options
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/pdb.py | 11 | ||||
-rw-r--r-- | Lib/pydoc_data/topics.py | 13 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 23 |
3 files changed, 38 insertions, 9 deletions
@@ -440,7 +440,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): self.message(repr(obj)) def default(self, line): - if line[:1] == '!': line = line[1:] + if line[:1] == '!': line = line[1:].strip() locals = self.curframe_locals globals = self.curframe.f_globals try: @@ -1642,9 +1642,12 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 resembles a debugger command. To - assign to a global variable you must always prefix the command - with a 'global' command, e.g.: + first word of the statement resembles a debugger command, e.g.: + (Pdb) ! n=42 + (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) """ diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py index 1babb5c..3aaaee6 100644 --- a/Lib/pydoc_data/topics.py +++ b/Lib/pydoc_data/topics.py @@ -5283,11 +5283,14 @@ topics = {'assert': 'The "assert" statement\n' 'current\n' ' stack frame. The exclamation point can be omitted unless the ' 'first\n' - ' word of the statement resembles a debugger command. To set ' - 'a\n' - ' global variable, you can prefix the assignment command with ' - 'a\n' - ' "global" statement on the same line, e.g.:\n' + ' word of the statement resembles a debugger command, e.g.:' + '\n' + ' (Pdb) ! n=42\n' + ' (Pdb)\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' " (Pdb) global list_options; list_options = ['-l']\n" ' (Pdb)\n' diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 482c92d..037673d 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1798,6 +1798,29 @@ def test_pdb_issue_gh_101517(): (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() class PdbTestCase(unittest.TestCase): |