]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-104301: Allow leading whitespace in disambiguated pdb statements (#104342)
authorJames Gerity <snoopjedi@gmail.com>
Thu, 11 May 2023 17:12:02 +0000 (13:12 -0400)
committerGitHub <noreply@github.com>
Thu, 11 May 2023 17:12:02 +0000 (18:12 +0100)
Doc/library/pdb.rst
Lib/pdb.py
Lib/pydoc_data/topics.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2023-05-09-18-46-24.gh-issue-104301.gNnbId.rst [new file with mode: 0644]

index 74bffef5562ae1d8aab5ca594e8edf5bb1a87d71..ef52370bff80583c9a984ded6676346eeaf32e85 100644 (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.
    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
-   assignment command with a :keyword:`global` statement on the same line,
-   e.g.::
+   resembles a debugger command, 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)
index b3dc5a455e56b91ebda8641cfa42b06eb216de55..6b6feac1ddead14ab2158b3236f750e445c65158 100755 (executable)
@@ -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)
         """
index 1babb5ce9476c92d192770caa6e57975a300f9dd..3aaaee67fa35a60b5389c28684ac50a8aeadcc30 100644 (file)
@@ -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'
index 482c92dbf1f6a0a7e7161a3affee68042bc8c2af..037673dd0ea80272b43a37fe197d6ca9dbf9a8b4 100644 (file)
@@ -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):
diff --git a/Misc/NEWS.d/next/Library/2023-05-09-18-46-24.gh-issue-104301.gNnbId.rst b/Misc/NEWS.d/next/Library/2023-05-09-18-46-24.gh-issue-104301.gNnbId.rst
new file mode 100644 (file)
index 0000000..a44ad76
--- /dev/null
@@ -0,0 +1 @@
+Allow leading whitespace in disambiguated statements in :mod:`pdb`.