From d4c6872cccf728f7e7052944dd40c2e8e7f33949 Mon Sep 17 00:00:00 2001 From: saucoide Date: Sat, 19 Jul 2025 15:36:41 +0200 Subject: [PATCH 1/8] gh-80744: do not read .pdbrc twice when cwd == $home --- Lib/pdb.py | 13 ++++++++----- Lib/test/test_pdb.py | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index fc83728fb6dc94..2a83375d12ce5b 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -378,11 +378,14 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, self.rcLines.extend(rcFile) except OSError: pass - try: - with open(".pdbrc", encoding='utf-8') as rcFile: - self.rcLines.extend(rcFile) - except OSError: - pass + if os.path.join( + os.path.abspath(os.curdir), ".pdbrc" + ) != os.path.expanduser("~/.pdbrc"): + try: + with open(".pdbrc", encoding='utf-8') as rcFile: + self.rcLines.extend(rcFile) + except OSError: + pass self.commands = {} # associates a command list to breakpoint numbers self.commands_defining = False # True while in the process of defining diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 6b74e21ad73d1a..0b86a1a2204fb8 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3935,6 +3935,25 @@ def test_readrc_homedir(self): f.write("invalid") self.assertEqual(pdb.Pdb().rcLines[0], "invalid") + def test_readrc_current_dir(self): + with os_helper.temp_cwd() as cwd: + rc_path = os.path.join(cwd, ".pdbrc") + with open(rc_path, "w") as f: + f.write("invalid") + self.assertEqual(pdb.Pdb().rcLines[0], "invalid") + self.assertEqual(len(pdb.Pdb().rcLines), 1) + + def test_readrc_home_twice(self): + with os_helper.EnvironmentVarGuard() as env: + env.unset("HOME") + with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"): + rc_path = os.path.join(cwd, ".pdbrc") + os.path.expanduser.return_value = rc_path + with open(rc_path, "w") as f: + f.write("invalid") + self.assertEqual(pdb.Pdb().rcLines, ["invalid"]) + self.assertEqual(len(pdb.Pdb().rcLines), 1) + def test_header(self): stdout = StringIO() header = 'Nobody expects... blah, blah, blah' From 53613ef3f8d4f809a72e19a0ba663e4a89735b14 Mon Sep 17 00:00:00 2001 From: saucoide Date: Wed, 23 Jul 2025 13:55:42 +0200 Subject: [PATCH 2/8] simplify path comparison --- Lib/pdb.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 2a83375d12ce5b..729f1e26add1c9 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -378,9 +378,7 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, self.rcLines.extend(rcFile) except OSError: pass - if os.path.join( - os.path.abspath(os.curdir), ".pdbrc" - ) != os.path.expanduser("~/.pdbrc"): + if os.path.abspath(".pdbrc") != os.path.expanduser("~/.pdbrc"): try: with open(".pdbrc", encoding='utf-8') as rcFile: self.rcLines.extend(rcFile) From 623d54db792139f6357f58ebf61ea0bb7f2ee25a Mon Sep 17 00:00:00 2001 From: saucoide Date: Thu, 24 Jul 2025 10:40:39 +0200 Subject: [PATCH 3/8] rename test --- Lib/test/test_pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 0b86a1a2204fb8..14ac144f209d58 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3943,7 +3943,7 @@ def test_readrc_current_dir(self): self.assertEqual(pdb.Pdb().rcLines[0], "invalid") self.assertEqual(len(pdb.Pdb().rcLines), 1) - def test_readrc_home_twice(self): + def test_readrc_cwd_is_home(self): with os_helper.EnvironmentVarGuard() as env: env.unset("HOME") with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"): From b8bb7a91dee9e92b68f82158a1f6e3474a086f42 Mon Sep 17 00:00:00 2001 From: saucoide Date: Thu, 24 Jul 2025 10:41:00 +0200 Subject: [PATCH 4/8] simplify asserts --- Lib/test/test_pdb.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 14ac144f209d58..d16475116e1a46 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3940,8 +3940,7 @@ def test_readrc_current_dir(self): rc_path = os.path.join(cwd, ".pdbrc") with open(rc_path, "w") as f: f.write("invalid") - self.assertEqual(pdb.Pdb().rcLines[0], "invalid") - self.assertEqual(len(pdb.Pdb().rcLines), 1) + self.assertEqual(pdb.Pdb().rcLines[-1], "invalid") def test_readrc_cwd_is_home(self): with os_helper.EnvironmentVarGuard() as env: @@ -3952,7 +3951,6 @@ def test_readrc_cwd_is_home(self): with open(rc_path, "w") as f: f.write("invalid") self.assertEqual(pdb.Pdb().rcLines, ["invalid"]) - self.assertEqual(len(pdb.Pdb().rcLines), 1) def test_header(self): stdout = StringIO() From e85c18108da312357453b86b2a269f42085c06ae Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 20 Dec 2025 16:35:43 +0000 Subject: [PATCH 5/8] =?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/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst diff --git a/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst b/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst new file mode 100644 index 00000000000000..83c9443030c49c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst @@ -0,0 +1 @@ +Fix issue where `pdb` would read a `pdbrc` twice if launched from the home directory From 04b788fd8b4bb53d33193556e2786fc91e986192 Mon Sep 17 00:00:00 2001 From: saucoide Date: Sat, 20 Dec 2025 17:22:34 +0100 Subject: [PATCH 6/8] reuse os.path calls --- Lib/pdb.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 6725907248e807..1f2d6eb67556a8 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -391,14 +391,18 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, # Read ~/.pdbrc and ./.pdbrc self.rcLines = [] if readrc: + home_rcfile = os.path.expanduser("~/.pdbrc") + local_rcfile = os.path.abspath(".pdbrc") + try: - with open(os.path.expanduser('~/.pdbrc'), encoding='utf-8') as rcFile: + with open(home_rcfile, encoding='utf-8') as rcFile: self.rcLines.extend(rcFile) except OSError: pass - if os.path.abspath(".pdbrc") != os.path.expanduser("~/.pdbrc"): + + if local_rcfile != home_rcfile: try: - with open(".pdbrc", encoding='utf-8') as rcFile: + with open(local_rcfile, encoding='utf-8') as rcFile: self.rcLines.extend(rcFile) except OSError: pass From 4058d33c77922da68aef59721e8af7b05fa96781 Mon Sep 17 00:00:00 2001 From: saucoide Date: Sat, 20 Dec 2025 17:40:52 +0100 Subject: [PATCH 7/8] rst'ing --- .../next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst b/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst index 83c9443030c49c..03ec9e4652b8cc 100644 --- a/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst +++ b/Misc/NEWS.d/next/Library/2025-12-20-16-35-42.gh-issue-80744.X4pZ2N.rst @@ -1 +1 @@ -Fix issue where `pdb` would read a `pdbrc` twice if launched from the home directory +Fix issue where ``pdb`` would read a ``.pdbrc`` twice if launched from the home directory From d3d79f8dfadccda03970e6c56543f2ea4a26d50b Mon Sep 17 00:00:00 2001 From: saucoide Date: Sun, 21 Dec 2025 13:28:58 +0100 Subject: [PATCH 8/8] rename rcFile to rcfile --- Lib/pdb.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 1f2d6eb67556a8..993ebc26c6469a 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -395,15 +395,15 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, local_rcfile = os.path.abspath(".pdbrc") try: - with open(home_rcfile, encoding='utf-8') as rcFile: - self.rcLines.extend(rcFile) + with open(home_rcfile, encoding='utf-8') as rcfile: + self.rcLines.extend(rcfile) except OSError: pass if local_rcfile != home_rcfile: try: - with open(local_rcfile, encoding='utf-8') as rcFile: - self.rcLines.extend(rcFile) + with open(local_rcfile, encoding='utf-8') as rcfile: + self.rcLines.extend(rcfile) except OSError: pass