8000 gh-100141: Allow pdb to deal with empty file (#125425) · python/cpython@bb9604b · GitHub
[go: up one dir, main page]

Skip to content

Commit bb9604b

Browse files
gh-100141: Allow pdb to deal with empty file (#125425)
1 parent c6e8ff8 commit bb9604b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Lib/pdb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ def user_call(self, frame, argument_list):
429429
def user_line(self, frame):
430430
"""This function is called when we stop or break at this line."""
431431
if self._wait_for_mainpyfile:
432-
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)
433-
or frame.f_lineno <= 0):
432+
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)):
434433
return
435434
self._wait_for_mainpyfile = False
436435
self.bp_commands(frame)

Lib/test/test_pdb.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,6 +3999,16 @@ def _create_fake_frozen_module():
39993999
# verify that pdb found the source of the "frozen" function
40004000
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
40014001

4002+
def test_empty_file(self):
4003+
script = ''
4004+
commands = 'q\n'
4005+
# We check that pdb stopped at line 0, but anything reasonable
4006+
# is acceptable here, as long as it does not halt
4007+
stdout, _ = self.run_pdb_script(script, commands)
4008+
self.assertIn('main.py(0)', stdout)
4009+
stdout, _ = self.run_pdb_module(script, commands)
4010+
self.assertIn('__main__.py(0)', stdout)
4011+
40024012
def test_non_utf8_encoding(self):
40034013
script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules')
40044014
for filename in os.listdir(script_dir):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the bug where :mod:`pdb` will be stuck in an infinite loop when debugging an empty file.

0 commit comments

Comments
 (0)
0