Skip to content

Commit 7dfb752

Browse files
author
sauco
committed
gh-80744: do not read .pdbrc twice when cwd == $home
1 parent 17ac393 commit 7dfb752

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

Lib/pdb.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,14 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
378378
self.rcLines.extend(rcFile)
379379
except OSError:
380380
pass
381-
try:
382-
with open(".pdbrc", encoding='utf-8') as rcFile:
383-
self.rcLines.extend(rcFile)
384-
except OSError:
385-
pass
381+
if os.path.join(
382+
os.path.abspath(os.curdir), ".pdbrc"
383+
) != os.path.expanduser("~/.pdbrc"):
384+
try:
385+
with open(".pdbrc", encoding='utf-8') as rcFile:
386+
self.rcLines.extend(rcFile)
387+
except OSError:
388+
pass
386389

387390
self.commands = {} # associates a command list to breakpoint numbers
388391
self.commands_defining = False # True while in the process of defining

Lib/test/test_pdb.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,6 +3935,25 @@ def test_readrc_homedir(self):
39353935
f.write("invalid")
39363936
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
39373937

3938+
def test_readrc_current_dir(self):
3939+
with os_helper.temp_cwd() as cwd:
3940+
rc_path = os.path.join(cwd, ".pdbrc")
3941+
with open(rc_path, "w") as f:
3942+
f.write("invalid")
3943+
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
3944+
self.assertEqual(len(pdb.Pdb().rcLines), 1)
3945+
3946+
def test_readrc_home_twice(self):
3947+
with os_helper.EnvironmentVarGuard() as env:
3948+
env.unset("HOME")
3949+
with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"):
3950+
rc_path = os.path.join(cwd, ".pdbrc")
3951+
os.path.expanduser.return_value = rc_path
3952+
with open(rc_path, "w") as f:
3953+
f.write("invalid")
3954+
self.assertEqual(pdb.Pdb().rcLines, ["invalid"])
3955+
self.assertEqual(len(pdb.Pdb().rcLines), 1)
3956+
39383957
def test_header(self):
39393958
stdout = StringIO()
39403959
header = 'Nobody expects... blah, blah, blah'

0 commit comments

Comments
 (0)