]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #16180: Exit pdb if file has syntax error, instead of trapping user
authorTerry Jan Reedy <tjreedy@udel.edu>
Sat, 5 Sep 2015 23:13:17 +0000 (19:13 -0400)
committerTerry Jan Reedy <tjreedy@udel.edu>
Sat, 5 Sep 2015 23:13:17 +0000 (19:13 -0400)
in an infinite loop.  Patch by Xavier de Gaye.

Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS

index 113b4e089271dff4d7bceed732bd68cdc71e957a..4d35103b90b694235836fc211556ce3b0161caa6 100755 (executable)
@@ -1322,6 +1322,9 @@ def main():
             # In most cases SystemExit does not warrant a post-mortem session.
             print "The program exited via sys.exit(). Exit status: ",
             print sys.exc_info()[1]
+        except SyntaxError:
+            traceback.print_exc()
+            sys.exit(1)
         except:
             traceback.print_exc()
             print "Uncaught exception. Entering post mortem debugging"
index b6dd2b7370dc8f53664fff68fc22cc753929404f..b98fe19816f7278c85cfd649ef47040aae3c0f71 100644 (file)
@@ -69,6 +69,17 @@ class PdbTestCase(unittest.TestCase):
             any('main.py(5)foo()->None' in l for l in stdout.splitlines()),
             'Fail to step into the caller after a return')
 
+    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))
+
 
 class PdbTestInput(object):
     """Context manager that makes testing Pdb in doctests easier."""
index e77ba3449f9663e644c4746ff2a49d4f8134c11a..017acc611d54244955ca86b059ffa117fd4a087d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #16180: Exit pdb if file has syntax error, instead of trapping user
+  in an infinite loop.  Patch by Xavier de Gaye.
+
 - Issue #22812: Fix unittest discovery examples.
   Patch from Pam McA'Nulty.