Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ca3f435

Browse files
committed
Issue #16180: Exit pdb if file has syntax error, instead of trapping user
in an infinite loop. Patch by Xavier de Gaye.
1 parent 6fb5bae commit ca3f435

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/pdb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,9 @@ def main():
16691669
# In most cases SystemExit does not warrant a post-mortem session.
16701670
print("The program exited via sys.exit(). Exit status:", end=' ')
16711671
print(sys.exc_info()[1])
1672+
except SyntaxError:
1673+
traceback.print_exc()
1674+
sys.exit(1)
16721675
except:
16731676
traceback.print_exc()
16741677
print("Uncaught exception. Entering post mortem debugging")

Lib/test/test_pdb.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,18 @@ def start_pdb():
10431043
self.assertNotIn('Error', stdout.decode(),
10441044
"Got an error running test script under PDB")
10451045

1046+
def test_issue16180(self):
1047+
# A syntax error in the debuggee.
1048+
script = "def f: pass\n"
1049+
commands = ''
1050+
expected = "SyntaxError:"
1051+
stdout, stderr = self.run_pdb(script, commands)
1052+
self.assertIn(expected, stdout,
1053+
'\n\nExpected:\n{}\nGot:\n{}\n'
1054+
'Fail to handle a syntax error in the debuggee.'
1055+
.format(expected, stdout))
1056+
1057+
10461058
def tearDown(self):
10471059
support.unlink(support.TESTFN)
10481060

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Core and Builtins
8181
Library
8282
-------
8383

84+
- Issue #16180: Exit pdb if file has syntax error, instead of trapping user
85+
in an infinite loop. Patch by Xavier de Gaye.
86+
8487
- Issue #21112: Fix regression in unittest.expectedFailure on subclasses.
8588
Patch from Berker Peksag.
8689

0 commit comments

Comments
 (0)