◐ Shell
clean mode source ↗

bpo-45249: Fix caret location when end_offset is set to 0 by pablogsal · Pull Request #28855 · python/cpython

Expand Up @@ -55,6 +55,9 @@ def syntax_error_with_caret_non_ascii(self): def syntax_error_bad_indentation2(self): compile(" print(2)", "?", "exec")
def tokenizer_error_with_caret_range(self): compile("blech ( ", "?", "exec")
def test_caret(self): err = self.get_exception_format(self.syntax_error_with_caret, SyntaxError) Expand Down Expand Up @@ -85,6 +88,13 @@ def test_caret(self): self.assertEqual(err[1].find("y"), err[2].find("^")) # in the right place self.assertEqual(err[2].count("^"), len("y for y in range(30)"))
err = self.get_exception_format(self.tokenizer_error_with_caret_range, SyntaxError) self.assertIn("^", err[2]) # third line has caret self.assertEqual(err[2].count('\n'), 1) # and no additional newline self.assertEqual(err[1].find("("), err[2].find("^")) # in the right place self.assertEqual(err[2].count("^"), 1)
def test_nocaret(self): exc = SyntaxError("error", ("x.py", 23, None, "bad syntax")) err = traceback.format_exception_only(SyntaxError, exc) Expand Down