Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-133357: Add anti-regression test for caret location in error message #133848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -3271,6 +3271,21 @@ def test_ifexp_body_stmt_else_stmt(self):
]:
self._check_error(f"x = {lhs_stmt} if 1 else {rhs_stmt}", msg)

def test_caret_location_invalid_star_expr(self):
# regression test for caret location, see #133357
with self.assertRaises(SyntaxError) as cm:
compile("A[*]", "<string>", "exec")
with self.assertRaises(SyntaxError) as cm2:
compile("A[*(1:2)] = 1", "<string>", "exec")
e = cm.exception
e2 = cm2.exception
self.assertEqual(e.msg, "Invalid star expression")
self.assertEqual(e.text.strip(), "A[*]")
self.assertEqual(e.offset, 4)
self.assertEqual(e2.msg, "Invalid star expression")
self.assertEqual(e2.text.strip(), "A[*(1:2)] = 1")
self.assertEqual(e2.offset, 6)

def load_tests(loader, tests, pattern):
tests.addTest(doctest.DocTestSuite())
return tests
Expand Down
Loading