Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-90095: Ignore empty lines and comments in .pdbrc #116834

Merged
merged 3 commits into from
Mar 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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.

Expand Down
5 changes: 4 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ def setup(self, f, tb):
)

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 @@ -2933,8 +2933,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

""")
iritkatriel marked this conversation as resolved.
Show resolved Hide resolved

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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore empty lines and comments in ``.pdbrc``
Loading