Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a50cf6c

Browse files
gh-90095: Ignore empty lines and comments in .pdbrc (#116834)
1 parent 8fc8fbb commit a50cf6c

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

Doc/library/pdb.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ There are three preset *convenience variables*:
288288

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

Lib/pdb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ def setup(self, f, tb):
364364
)
365365

366366
if self.rcLines:
367-
self.cmdqueue = self.rcLines
367+
self.cmdqueue = [
368+
line for line in self.rcLines
369+
if line.strip() and not line.strip().startswith("#")
370+
]
368371
self.rcLines = []
369372

370373
# Override Bdb methods

Lib/test/test_pdb.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,8 +2933,27 @@ def test_pdbrc_basic(self):
29332933
""")
29342934

29352935
stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
2936+
self.assertNotIn("SyntaxError", stdout)
29362937
self.assertIn("a+8=9", stdout)
29372938

2939+
def test_pdbrc_empty_line(self):
2940+
"""Test that empty lines in .pdbrc are ignored."""
2941+
2942+
script = textwrap.dedent("""
2943+
a = 1
2944+
b = 2
2945+
c = 3
2946+
""")
2947+
2948+
pdbrc = textwrap.dedent("""
2949+
n
2950+
2951+
""")
2952+
2953+
stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
2954+
self.assertIn("b = 2", stdout)
2955+
self.assertNotIn("c = 3", stdout)
2956+
29382957
def test_pdbrc_alias(self):
29392958
script = textwrap.dedent("""
29402959
class A:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ignore empty lines and comments in ``.pdbrc``

0 commit comments

Comments
 (0)