Skip to content

Commit 5b93cce

Browse files
Align more parser/SyntaxError messages with CPython 3.14.5
Continues RustPython#7928/RustPython#7933/RustPython#7988. Translates many more ruff ParseErrorType variants to CPython's exact wording in CompileError::from_ruff_parse_error, and routes ast.parse() / compile(PyCF_ONLY_AST) through the same path so those messages match too (previously they leaked raw ruff strings). Adds a few codegen/symtable checks. Covered: aug-assign/delete/set/dict/f-string/t-string targets; "cannot use {kind} as import target"; string-prefix incompatibility and "invalid character 'X' (U+XXXX)"; parenthesized def/lambda params; missing default/argument value; dict ':' / value syntax; "'elif' block follows an 'else' block"; raise-from; comprehension 'if'; ternary statement keywords; match "case ... as <target>" -> "cannot use {kind} as pattern target" and "case ... as _"; __debug__ as def/class/type-param/except name; "name 'x' is nonlocal and global"; generic type-parameter wording. Lib/test: drop the now-passing "# TODO: RUSTPYTHON; Wrong error message" doctest markers and @expectedfailure decorators. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1385c4e commit 5b93cce

11 files changed

Lines changed: 1987 additions & 288 deletions

File tree

‎Lib/test/test_genexps.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
...
160160
SyntaxError: cannot assign to generator expression
161161
162-
>>> (y for y in (1,2)) += 10 # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
162+
>>> (y for y in (1,2)) += 10
163163
Traceback (most recent call last):
164164
...
165165
SyntaxError: 'generator expression' is an illegal expression for augmented assignment

‎Lib/test/test_named_expressions.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,30 @@
44

55
class NamedExpressionInvalidTest(unittest.TestCase):
66

7-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
87
def test_named_expression_invalid_01(self):
98
code = """x := 0"""
109

1110
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
1211
exec(code, {}, {})
1312

14-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
1513
def test_named_expression_invalid_02(self):
1614
code = """x = y := 0"""
1715

1816
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
1917
exec(code, {}, {})
2018

21-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
2219
def test_named_expression_invalid_03(self):
2320
code = """y := f(x)"""
2421

2522
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
2623
exec(code, {}, {})
2724

28-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
2925
def test_named_expression_invalid_04(self):
3026
code = """y0 = y1 := f(x)"""
3127

3228
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
3329
exec(code, {}, {})
3430

35-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
3631
def test_named_expression_invalid_06(self):
3732
code = """((a, b) := (1, 2))"""
3833

@@ -103,7 +98,6 @@ def test_named_expression_invalid_16(self):
10398
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
10499
exec(code, {}, {})
105100

106-
@unittest.expectedFailure # TODO: RUSTPYTHON
107101
def test_named_expression_invalid_17(self):
108102
code = "[i := 0, j := 1 for i, j in [(1, 2), (3, 4)]]"
109103

‎Lib/test/test_patma.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,6 @@ def test_invalid_syntax_2(self):
29552955
pass
29562956
""")
29572957

2958-
@unittest.expectedFailure # TODO: RUSTPYTHON
29592958
def test_invalid_syntax_3(self):
29602959
self.assert_syntax_error("""
29612960
match ...:

0 commit comments

Comments
 (0)