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

This commit is contained in:
Tian Gao 2024-03-15 02:36:04 -07:00 committed by GitHub
parent 8fc8fbb43a
commit a50cf6c3d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View File

@ -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.

View File

@ -364,7 +364,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
)
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

View File

@ -2933,8 +2933,27 @@ def bœr():
""")
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:

View File

@ -0,0 +1 @@
Ignore empty lines and comments in ``.pdbrc``