https://github.com/python/cpython/commit/abd079806d5f676410fbeaf1a7980f75f85833f7
commit: abd079806d5f676410fbeaf1a7980f75f85833f7
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: iritkatriel <[email protected]>
date: 2024-03-15T09:52:00Z
summary:

[3.12] gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834) 
(#116854)

gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834)
(cherry picked from commit a50cf6c3d76b34e2ee9f92a248f1b0df24e407f6)

Co-authored-by: Tian Gao <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst
M Doc/library/pdb.rst
M Lib/pdb.py
M Lib/test/test_pdb.py

diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst
index d9cb9a4ecb1b3c..b8f15aaa5a9a09 100644
--- a/Doc/library/pdb.rst
+++ b/Doc/library/pdb.rst
@@ -284,7 +284,8 @@ There are three preset *convenience variables*:
 
 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.
 
diff --git a/Lib/pdb.py b/Lib/pdb.py
index b76a6831525713..225c9f253ef310 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -301,7 +301,10 @@ def setup(self, f, tb):
         self.set_convenience_variable(self.curframe, '_frame', self.curframe)
 
         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
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index db30412f55a345..5bdc5f22d0b798 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -2212,8 +2212,27 @@ def test_pdbrc_basic(self):
         """)
 
         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
index 00000000000000..b7024c74f7aa7d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst
@@ -0,0 +1 @@
+Ignore empty lines and comments in ``.pdbrc``

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to