From b9e2f89cd145bc9f1ede14fc2e8e1ef57b4541d9 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 23 Aug 2024 02:25:33 +0300 Subject: [PATCH] gh-122546: Relax SyntaxError check when raising errors on the new REPL (GH-123233) (cherry picked from commit 4c3f0cbeaec0d49212d305618743fabb0e74a696) Co-authored-by: Sergey B Kirpichev --- Lib/code.py | 2 +- Lib/test/test_pyrepl/test_pyrepl.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/code.py b/Lib/code.py index 5f7a2d3be07cad..25f5b6a577fff8 100644 --- a/Lib/code.py +++ b/Lib/code.py @@ -110,7 +110,7 @@ def showsyntaxerror(self, filename=None, **kwargs): colorize = kwargs.pop('colorize', False) try: typ, value, tb = sys.exc_info() - if filename and typ is SyntaxError: + if filename and issubclass(typ, SyntaxError): value.filename = filename source = kwargs.pop('source', "") self._showtraceback(typ, value, None, colorize, source) diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index a433212fe92ddc..9944cd08dd5162 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -1109,6 +1109,10 @@ def test_correct_filename_in_syntaxerrors(self): self.skipTest("pyrepl not available") self.assertIn("SyntaxError: invalid syntax", output) self.assertIn("", output) + commands = " b\nexit()\n" + output, exit_code = self.run_repl(commands, env=env) + self.assertIn("IndentationError: unexpected indent", output) + self.assertIn("", output) def run_repl( self,