8000 [3.12] gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-1168… · python/cpython@abd0798 · GitHub
[go: up one dir, main page]

Skip to content

Commit abd0798

Browse files
[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 a50cf6c) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent 3751411 commit abd0798

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
@@ -284,7 +284,8 @@ There are three preset *convenience variables*:
284284

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

Lib/pdb.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ def setup(self, f, tb):
301301
self.set_convenience_variable(self.curframe, '_frame', self.curframe)
302302

303303
if self.rcLines:
304-
self.cmdqueue = self.rcLines
304+
self.cmdqueue = [
305+
line for line in self.rcLines
306+
if line.strip() and not line.strip().startswith("#")
307+
]
305308
self.rcLines = []
306309

307310
# Override Bdb methods

Lib/test/test_pdb.py

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

22142214
stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
2215+
self.assertNotIn("SyntaxError", stdout)
22152216
self.assertIn("a+8=9", stdout)
22162217

2218+
def test_pdbrc_empty_line(self):
2219+
"""Test that empty lines in .pdbrc are ignored."""
2220+
2221+
script = textwrap.dedent("""
2222+
a = 1
2223+
b = 2
2224+
c = 3
2225+
""")
2226+
2227+
pdbrc = textwrap.dedent("""
2228+
n
2229+
2230+
""")
2231+
2232+
stdout, stderr = self.run_pdb_script(script, 'q\n', pdbrc=pdbrc, remove_home=True)
2233+
self.assertIn("b = 2", stdout)
2234+
self.assertNotIn("c = 3", stdout)
2235+
22172236
def test_pdbrc_alias(self):
22182237
script = textwrap.dedent("""
22192238
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)
0