From 128e8132bab2ee821673f22b9f9a22ba4405e851 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 7 Feb 2019 16:54:21 +0100 Subject: [PATCH 1/5] pdb: do_debug: handle SyntaxError On the pdb prompt `debug print(` currently crashes, but `print(` displays that there's a SyntaxError. This patch fixes this by pre-compiling the code for `Pdb.run`. --- Lib/pdb.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index 60bdb7675c81316..1443f9f85c7e123 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -1093,10 +1093,16 @@ def do_debug(self, arg): sys.settrace(None) globals = self.curframe.f_globals locals = self.curframe_locals + try: + code = compile(arg, "", "exec") + except SyntaxError: + exc_info = sys.exc_info()[:2] + self.error(traceback.format_exception_only(*exc_info)[-1].strip()) + return p = Pdb(self.completekey, self.stdin, self.stdout) p.prompt = "(%s) " % self.prompt.strip() self.message("ENTERING RECURSIVE DEBUGGER") - sys.call_tracing(p.run, (arg, globals, locals)) + sys.call_tracing(p.run, (code, globals, locals)) self.message("LEAVING RECURSIVE DEBUGGER") sys.settrace(self.trace_dispatch) self.lastcmd = p.lastcmd From 0230f3e60e98f0a89c42ca3a5ffecf87c148bf5e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Thu, 7 Feb 2019 16:22:51 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst diff --git a/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst b/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst new file mode 100644 index 000000000000000..b87cb0a89552a2d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst @@ -0,0 +1 @@ +pdb: handle SyntaxError with ``debug``. \ No newline at end of file From 77991dbf9a8bcd87dd5ad5aa8f72a0005179cad7 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 7 Feb 2019 17:21:36 +0100 Subject: [PATCH 3/5] fixup! pdb: do_debug: handle SyntaxError --- Lib/test/test_pdb.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 4f9d28afd3b5b49..6f952e9193f1903 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1486,6 +1486,14 @@ def test_relative_imports_on_plain_module(self): stdout, _ = self._run_pdb(['-m', self.module_name + '.runme'], commands) self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) + def test_syntaxerror(self): + stdout, _ = self.run_pdb_module("", "print(") + self.assertIn('(Pdb) *** SyntaxError: unexpected EOF while parsing\n(Pdb) ', stdout) + + def test_syntaxerror_debug(self): + stdout, _ = self.run_pdb_module("", "debug print(") + self.assertIn('(Pdb) *** SyntaxError: unexpected EOF while parsing\n(Pdb) ', stdout) + def load_tests(*args): from test import test_pdb From 256699b884a33446723858f2ef7fb13343d3848c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 8 Feb 2019 15:53:18 +0100 Subject: [PATCH 4/5] fixup! fixup! pdb: do_debug: handle SyntaxError --- Lib/test/test_pdb.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 6f952e9193f1903..21f6b7079bb54e3 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1486,14 +1486,14 @@ def test_relative_imports_on_plain_module(self): stdout, _ = self._run_pdb(['-m', self.module_name + '.runme'], commands) self.assertTrue(any("VAR from module" in l for l in stdout.splitlines()), stdout) - def test_syntaxerror(self): - stdout, _ = self.run_pdb_module("", "print(") - self.assertIn('(Pdb) *** SyntaxError: unexpected EOF while parsing\n(Pdb) ', stdout) - - def test_syntaxerror_debug(self): - stdout, _ = self.run_pdb_module("", "debug print(") - self.assertIn('(Pdb) *** SyntaxError: unexpected EOF while parsing\n(Pdb) ', stdout) - + def test_syntaxerror_in_command(self): + commands = "print(\ndebug print(" + stdout, _ = self.run_pdb_script("", commands) + self.assertEqual(stdout.splitlines()[1:], [ + '(Pdb) *** SyntaxError: unexpected EOF while parsing', + '(Pdb) *** SyntaxError: unexpected EOF while parsing', + '(Pdb) ', + ]) def load_tests(*args): from test import test_pdb From 8599e616eb0675aeeae8c15e99d2f5c7674d4c81 Mon Sep 17 00:00:00 2001 From: Zachary Ware Date: Fri, 15 Feb 2019 14:32:21 -0600 Subject: [PATCH 5/5] Reword news entry --- .../next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst b/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst index b87cb0a89552a2d..a229968583d1a4c 100644 --- a/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst +++ b/Misc/NEWS.d/next/Library/2019-02-07-16-22-50.bpo-35931._63i7B.rst @@ -1 +1 @@ -pdb: handle SyntaxError with ``debug``. \ No newline at end of file +The :mod:`pdb` ``debug`` command now gracefully handles syntax errors.