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 6c79bae

Browse filesBrowse files
[3.13] gh-100141: Allow pdb to deal with empty file (GH-125425) (#125536)
gh-100141: Allow pdb to deal with empty file (GH-125425) (cherry picked from commit bb9604b) Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent cc66dfc commit 6c79bae
Copy full SHA for 6c79bae

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
if 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
@@ -3781,6 +3781,16 @@ def _create_fake_frozen_module():
37813781
# verify that pdb found the source of the "frozen" function
37823782
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
37833783

3784+
def test_empty_file(self):
3785+
script = ''
3786+
commands = 'q\n'
3787+
# We check that pdb stopped at line 0, but anything reasonable
3788+
# is acceptable here, as long as it does not halt
3789+
stdout, _ = self.run_pdb_script(script, commands)
3790+
self.assertIn('main.py(0)', stdout)
3791+
stdout, _ = self.run_pdb_module(script, commands)
3792+
self.assertIn('__main__.py(0)', stdout)
3793+
37843794
def test_non_utf8_encoding(self):
37853795
script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules')
37863796
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.