Skip to content

Commit eaefa0b

Browse files
[3.11] gh-90095: Ignore empty lines and comments in .pdbrc (GH-116834) (#116855)
gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834) (cherry picked from commit a50cf6c) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent d83b4c5 commit eaefa0b

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

Doc/library/pdb.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ is to use implicit string concatenation ``';'';'`` or ``";"";"``.
269269

270270
If a file :file:`.pdbrc` exists in the user's home directory or in the current
271271
directory, it is read with ``'utf-8'`` encoding and executed as if it had been
272-
typed at the debugger prompt. This is particularly useful for aliases. If both
272+
typed at the debugger prompt, with the exception that empty lines and lines
273+
starting with ``#`` are ignored. This is particularly useful for aliases. If both
273274
files exist, the one in the home directory is read first and aliases defined there
274275
can be overridden by the local file.
275276

Lib/pdb.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,10 @@ def setup(self, f, tb):
297297
self.curframe_locals = self.curframe.f_locals
298298

299299
if self.rcLines:
300-
self.cmdqueue = self.rcLines
300+
self.cmdqueue = [
301+
line for line in self.rcLines
302+
if line.strip() and not line.strip().startswith("#")
303+
]
301304
self.rcLines = []
302305

303306
# Override Bdb methods

Lib/test/test_pdb.py

+19
Original file line numberDiff line numberDiff line change
@@ -2061,8 +2061,27 @@ def test_pdbrc_basic(self):
20612061
""")
20622062

20632063
stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
2064+
self.assertNotIn("SyntaxError", stdout)
20642065
self.assertIn("a+8=9", stdout)
20652066

2067+
def test_pdbrc_empty_line(self):
2068+
"""Test that empty lines in .pdbrc are ignored."""
2069+
2070+
script = textwrap.dedent("""
2071+
a = 1
2072+
b = 2
2073+
c = 3
2074+
""")
2075+
2076+
pdbrc = textwrap.dedent("""
2077+
n
2078+
2079+
""")
2080+
2081+
stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
2082+
self.assertIn("b = 2", stdout)
2083+
self.assertNotIn("c = 3", stdout)
2084+
20662085
def test_pdbrc_alias(self):
20672086
script = textwrap.dedent("""
20682087
class A:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore empty lines and comments in ``.pdbrc``

0 commit comments

Comments
 (0)