Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb9604b

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

File tree

Expand file treeCollapse file tree

3 files changed

+12
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+12
-2
lines changed

‎Lib/pdb.py

Copy file name to clipboardExpand all lines: Lib/pdb.py
+1-2Lines 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

Copy file name to clipboardExpand all lines: Lib/test/test_pdb.py
+10Lines 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):
+1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.