[Python-checkins] cpython (2.7): Issue #16180: Exit pdb if file has syntax error, instead of trapping user

terry.reedy python-checkins at python.org
Sun Sep 6 01:19:02 CEST 2015


https://hg.python.org/cpython/rev/26c4db1a0aea
changeset:   97686:26c4db1a0aea
branch:      2.7
parent:      97667:0ff7aa9a438f
user:        Terry Jan Reedy <tjreedy at udel.edu>
date:        Sat Sep 05 19:13:17 2015 -0400
summary:
  Issue #16180: Exit pdb if file has syntax error, instead of trapping user
in an infinite loop.  Patch by Xavier de Gaye.

files:
  Lib/pdb.py           |   3 +++
  Lib/test/test_pdb.py |  11 +++++++++++
  Misc/NEWS            |   3 +++
  3 files changed, 17 insertions(+), 0 deletions(-)


diff --git a/Lib/pdb.py b/Lib/pdb.py
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1322,6 +1322,9 @@
             # 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"
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -69,6 +69,17 @@
             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."""
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -37,6 +37,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 #22812: Fix unittest discovery examples.
   Patch from Pam McA'Nulty.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list