From 017aa25777a8302af15aebef000f2e72a1824e6c Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 14 Mar 2024 13:57:18 -0700 Subject: [PATCH 1/3] Fix pdbrc for empty lines/comments --- Doc/library/pdb.rst | 3 ++- Lib/pdb.py | 5 ++++- Lib/test/test_pdb.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst index 1cfca0cf68a946..ac3007f70c3534 100644 --- a/Doc/library/pdb.rst +++ b/Doc/library/pdb.rst @@ -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. diff --git a/Lib/pdb.py b/Lib/pdb.py index f4d19386703de0..88ea900e63f42b 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -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 diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 44728542787423..546e51a1252048 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2933,8 +2933,28 @@ 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 + """) + + # The empty lines need to have the same indentation as the other lines + 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: From e656e4f26c55378b9e25264766afca832cf3c5d8 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:59:30 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst diff --git a/Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst b/Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst new file mode 100644 index 00000000000000..b7024c74f7aa7d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-03-14-20-59-28.gh-issue-90095.7UaJ1U.rst @@ -0,0 +1 @@ +Ignore empty lines and comments in ``.pdbrc`` From 28e8312b6ed11b37df0783d73dcbb8e89c877dc3 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 14 Mar 2024 17:21:49 -0700 Subject: [PATCH 3/3] Remove unnecessary comments --- Lib/test/test_pdb.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 546e51a1252048..69691e930562bc 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2945,7 +2945,6 @@ def test_pdbrc_empty_line(self): c = 3 """) - # The empty lines need to have the same indentation as the other lines pdbrc = textwrap.dedent(""" n