]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834) (#116855)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 15 Mar 2024 09:55:44 +0000 (10:55 +0100)
committerGitHub <noreply@github.com>
Fri, 15 Mar 2024 09:55:44 +0000 (09:55 +0000)
gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834)
(cherry picked from commit a50cf6c3d76b34e2ee9f92a248f1b0df24e407f6)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Doc/library/pdb.rst
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst [new file with mode: 0644]

index a845d5512ff1e531a4b55151a26867eb54e5172a..1a949a2679dae4ef82ea008020509eecad59584a 100644 (file)
@@ -269,7 +269,8 @@ is to use implicit string concatenation ``';'';'`` or ``";"";"``.
 
 If a file :file:`.pdbrc` exists in the user's home directory or in the current
 directory, it is read with ``'utf-8'`` encoding and executed as if it had been
-typed at the debugger prompt.  This is particularly useful for aliases.  If both
+typed at the debugger prompt, with the exception that empty lines and lines
+starting with ``#`` are ignored.  This is particularly useful for aliases.  If both
 files exist, the one in the home directory is read first and aliases defined there
 can be overridden by the local file.
 
index fd73f14a7ea66a3e6fb6b6c1891007fe7c1805fd..3077b0bfa523e463c463d374b24fa3e7e22d9060 100755 (executable)
@@ -297,7 +297,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
         self.curframe_locals = self.curframe.f_locals
 
         if self.rcLines:
-            self.cmdqueue = self.rcLines
+            self.cmdqueue = [
+                line for line in self.rcLines
+                if line.strip() and not line.strip().startswith("#")
+            ]
             self.rcLines = []
 
     # Override Bdb methods
index 941031a5a9f6c20723a5eb3501af967bff60c9ee..d21ea9e5f7cddcf5b7ede4ff3e3cdadc81c0457d 100644 (file)
@@ -2061,8 +2061,27 @@ def bœr():
         """)
 
         stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
+        self.assertNotIn("SyntaxError", stdout)
         self.assertIn("a+8=9", stdout)
 
+    def test_pdbrc_empty_line(self):
+        """Test that empty lines in .pdbrc are ignored."""
+
+        script = textwrap.dedent("""
+            a = 1
+            b = 2
+            c = 3
+        """)
+
+        pdbrc = textwrap.dedent("""
+            n
+
+        """)
+
+        stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
+        self.assertIn("b = 2", stdout)
+        self.assertNotIn("c = 3", stdout)
+
     def test_pdbrc_alias(self):
         script = textwrap.dedent("""
             class A:
diff --git a/Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst b/Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst
new file mode 100644 (file)
index 0000000..b7024c7
--- /dev/null
@@ -0,0 +1 @@
+Ignore empty lines and comments in ``.pdbrc``