mirror of
https://github.com/python/cpython.git
synced 2026-04-13 15:20:52 +00:00
[3.11] gh-90095: Ignore empty lines and comments in .pdbrc (GH-116834) (#116855)
gh-90095: Ignore empty lines and comments in `.pdbrc` (GH-116834)
(cherry picked from commit a50cf6c3d7)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
d83b4c570c
commit
eaefa0b1f7
4 changed files with 26 additions and 2 deletions
|
|
@ -269,7 +269,8 @@ is to use implicit string concatenation ``';'';'`` or ``";"";"``.
|
|||
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
Ignore empty lines and comments in ``.pdbrc``
|
||||
Loading…
Add table
Add a link
Reference in a new issue