[3.11] gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834) by miss-islington · Pull Request #116855 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Doc/library/pdb.rst
5 changes: 4 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def setup(self, f, tb):
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
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2061,8 +2061,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:
Expand Down