Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
# Read $HOME/.pdbrc and ./.pdbrc
self.rcLines = []
if readrc:
readrcFiles = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small neat: please use name_with_underscores instead of camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asvetlov
I've tried to keep the style of the other vars there.
Can change it, but want to make sure it is really wanted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.rcLines exists starting from 2001.
Too late to change the name, it is a part of public API for good or for bad.
But for new variables better to follow PEP 8 style.

if 'HOME' in os.environ:
envHome = os.environ['HOME']
readrcFiles.append(os.path.join(envHome, ".pdbrc"))
if not readrcFiles or envHome != os.getcwd():
readrcFiles.append(".pdbrc")
for rcPath in readrcFiles:
try:
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
with open(rcPath) as rcFile:
self.rcLines.extend(rcFile)
except OSError:
pass
try:
with open(".pdbrc") as rcFile:
self.rcLines.extend(rcFile)
except OSError:
pass

self.commands = {} # associates a command list to breakpoint numbers
self.commands_doprompt = {} # for each bp num, tells if the prompt
Expand Down
27 changes: 27 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,33 @@ def test_readrc_kwarg(self):
if save_home is not None:
os.environ['HOME'] = save_home

def test_readrc_home_twice(self):
script = textwrap.dedent("""
import pdb; pdb.Pdb(readrc=True).set_trace()

print('hello')
""")

with support.temp_cwd() as cur_dir:
with patch.dict(os.environ, {'HOME': cur_dir}):
with open('.pdbrc', 'w') as f:
f.write("invalid\n")

with open('main.py', 'w') as f:
f.write(script)

cmd = [sys.executable, 'main.py']
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
)
with proc:
stdout, stderr = proc.communicate(b'q\n')
output = stdout.decode()
self.assertEqual(output.count('NameError'), 1)

def test_header(self):
stdout = StringIO()
header = 'Nobody expects... blah, blah, blah'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.pdbrc is not read twice anymore when the current directory is $HOME.