changeset: 97687:2d4aac2ab253 branch: 3.4 parent: 97671:e67bf9c9a898 user: Terry Jan Reedy date: Sat Sep 05 19:13:26 2015 -0400 files: Lib/pdb.py Lib/test/test_pdb.py Misc/NEWS description: Issue #16180: Exit pdb if file has syntax error, instead of trapping user in an infinite loop. Patch by Xavier de Gaye. diff -r e67bf9c9a898 -r 2d4aac2ab253 Lib/pdb.py --- a/Lib/pdb.py Fri Sep 04 17:27:49 2015 +0200 +++ b/Lib/pdb.py Sat Sep 05 19:13:26 2015 -0400 @@ -1669,6 +1669,9 @@ # In most cases SystemExit does not warrant a post-mortem session. print("The program exited via sys.exit(). Exit status:", end=' ') print(sys.exc_info()[1]) + except SyntaxError: + traceback.print_exc() + sys.exit(1) except: traceback.print_exc() print("Uncaught exception. Entering post mortem debugging") diff -r e67bf9c9a898 -r 2d4aac2ab253 Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py Fri Sep 04 17:27:49 2015 +0200 +++ b/Lib/test/test_pdb.py Sat Sep 05 19:13:26 2015 -0400 @@ -1043,6 +1043,18 @@ self.assertNotIn('Error', stdout.decode(), "Got an error running test script under PDB") + def test_issue16180(self): + # A syntax error in the debuggee. + script = "def f: pass\n" + commands = '' + expected = "SyntaxError:" + stdout, stderr = self.run_pdb(script, commands) + self.assertIn(expected, stdout, + '\n\nExpected:\n{}\nGot:\n{}\n' + 'Fail to handle a syntax error in the debuggee.' + .format(expected, stdout)) + + def tearDown(self): support.unlink(support.TESTFN) diff -r e67bf9c9a898 -r 2d4aac2ab253 Misc/NEWS --- a/Misc/NEWS Fri Sep 04 17:27:49 2015 +0200 +++ b/Misc/NEWS Sat Sep 05 19:13:26 2015 -0400 @@ -81,6 +81,9 @@ Library ------- +- Issue #16180: Exit pdb if file has syntax error, instead of trapping user + in an infinite loop. Patch by Xavier de Gaye. + - Issue #21112: Fix regression in unittest.expectedFailure on subclasses. Patch from Berker Peksag.