]> 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:26 +0000 (19:13 -0400)
committerTerry Jan Reedy <tjreedy@udel.edu>
Sat, 5 Sep 2015 23:13:26 +0000 (19:13 -0400)
in an infinite loop.  Patch by Xavier de Gaye.

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

index e28564bdfa3bcd4b9f9385e54d6fae9287343532..7d58c2ab43ff89f6e2eed783de9fcc9f9a87e4a3 100755 (executable)
@@ -1669,6 +1669,9 @@ def main():
             # 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")
index ec8346c5eeb0250e6f9896644e6dad473d60c899..35044ad2a13c33ba7dbfe2acd0484598ef2c1a67 100644 (file)
@@ -1043,6 +1043,18 @@ class PdbTestCase(unittest.TestCase):
         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)
 
index 66780edd2709afad717a1b1622e3c98ab27a92e5..dd175fead46e030d58893938c2bb7a1795a7d149 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,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 #21112: Fix regression in unittest.expectedFailure on subclasses.
   Patch from Berker Peksag.