Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0063a6d

Browse filesBrowse files
authored
Align more error messages with CPython 3.14.5 (RustPython#7928)
1 parent cea21f9 commit 0063a6d
Copy full SHA for 0063a6d

6 files changed

+252-216Lines changed: 252 additions & 216 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_metaclass.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_metaclass.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
129129
Check for duplicate keywords.
130130
131-
>>> class C(metaclass=type, metaclass=type): pass # TODO: RUSTPYTHON # doctest: +EXPECTED_FAILURE
131+
>>> class C(metaclass=type, metaclass=type): pass
132132
...
133133
Traceback (most recent call last):
134134
[...]
Collapse file

‎Lib/test/test_named_expressions.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_named_expressions.py
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,20 @@ def test_named_expression_invalid_10(self):
6363
with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
6464
exec(code, {}, {})
6565

66-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
6766
def test_named_expression_invalid_11(self):
6867
code = """spam(a=1, b := 2)"""
6968

7069
with self.assertRaisesRegex(SyntaxError,
7170
"positional argument follows keyword argument"):
7271
exec(code, {}, {})
7372

74-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
7573
def test_named_expression_invalid_12(self):
7674
code = """spam(a=1, (b := 2))"""
7775

7876
with self.assertRaisesRegex(SyntaxError,
7977
"positional argument follows keyword argument"):
8078
exec(code, {}, {})
8179

82-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
8380
def test_named_expression_invalid_13(self):
8481
code = """spam(a=1, (b := 2))"""
8582

Collapse file

‎Lib/test/test_positional_only_arg.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_positional_only_arg.py
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def assertRaisesSyntaxError(self, codestr, regex="invalid syntax"):
2323
with self.assertRaisesRegex(SyntaxError, regex):
2424
compile(codestr + "\n", "<test>", "single")
2525

26-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
2726
def test_invalid_syntax_errors(self):
2827
check_syntax_error(self, "def f(a, b = 5, /, c): pass", "parameter without a default follows parameter with a default")
2928
check_syntax_error(self, "def f(a = 5, b, /, c): pass", "parameter without a default follows parameter with a default")
@@ -46,7 +45,6 @@ def test_invalid_syntax_errors(self):
4645
check_syntax_error(self, "def f(a, /, c, /, d, *, e): pass")
4746
check_syntax_error(self, "def f(a, *, c, /, d, e): pass")
4847

49-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
5048
def test_invalid_syntax_errors_async(self):
5149
check_syntax_error(self, "async def f(a, b = 5, /, c): pass", "parameter without a default follows parameter with a default")
5250
check_syntax_error(self, "async def f(a = 5, b, /, c): pass", "parameter without a default follows parameter with a default")
@@ -235,7 +233,6 @@ def test_lambdas(self):
235233
x = lambda a, b, /, : a + b
236234
self.assertEqual(x(1, 2), 3)
237235

238-
@unittest.expectedFailure # TODO: RUSTPYTHON; wrong error message
239236
def test_invalid_syntax_lambda(self):
240237
check_syntax_error(self, "lambda a, b = 5, /, c: None", "parameter without a default follows parameter with a default")
241238
check_syntax_error(self, "lambda a = 5, b, /, c: None", "parameter without a default follows parameter with a default")
Collapse file

‎Lib/test/test_syntax.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_syntax.py
+45-51Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,12 @@
398398
399399
From ast_for_arguments():
400400
401-
>>> def f(x, y=1, z): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
401+
>>> def f(x, y=1, z):
402402
... pass
403403
Traceback (most recent call last):
404404
SyntaxError: parameter without a default follows parameter with a default
405405
406-
>>> def f(x, /, y=1, z): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
406+
>>> def f(x, /, y=1, z):
407407
... pass
408408
Traceback (most recent call last):
409409
SyntaxError: parameter without a default follows parameter with a default
@@ -423,47 +423,47 @@
423423
Traceback (most recent call last):
424424
SyntaxError: invalid syntax
425425
426-
>>> def foo(/,a,b=,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
426+
>>> def foo(/,a,b=,c):
427427
... pass
428428
Traceback (most recent call last):
429429
SyntaxError: at least one argument must precede /
430430
431-
>>> def foo(a,/,/,b,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
431+
>>> def foo(a,/,/,b,c):
432432
... pass
433433
Traceback (most recent call last):
434434
SyntaxError: / may appear only once
435435
436-
>>> def foo(a,/,a1,/,b,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
436+
>>> def foo(a,/,a1,/,b,c):
437437
... pass
438438
Traceback (most recent call last):
439439
SyntaxError: / may appear only once
440440
441-
>>> def foo(a=1,/,/,*b,/,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
441+
>>> def foo(a=1,/,/,*b,/,c):
442442
... pass
443443
Traceback (most recent call last):
444444
SyntaxError: / may appear only once
445445
446-
>>> def foo(a,/,a1=1,/,b,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
446+
>>> def foo(a,/,a1=1,/,b,c):
447447
... pass
448448
Traceback (most recent call last):
449449
SyntaxError: / may appear only once
450450
451-
>>> def foo(a,*b,c,/,d,e): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
451+
>>> def foo(a,*b,c,/,d,e):
452452
... pass
453453
Traceback (most recent call last):
454454
SyntaxError: / must be ahead of *
455455
456-
>>> def foo(a=1,*b,c=3,/,d,e): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
456+
>>> def foo(a=1,*b,c=3,/,d,e):
457457
... pass
458458
Traceback (most recent call last):
459459
SyntaxError: / must be ahead of *
460460
461-
>>> def foo(a,*b=3,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
461+
>>> def foo(a,*b=3,c):
462462
... pass
463463
Traceback (most recent call last):
464464
SyntaxError: var-positional argument cannot have default value
465465
466-
>>> def foo(a,*b: int=,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
466+
>>> def foo(a,*b: int=,c):
467467
... pass
468468
Traceback (most recent call last):
469469
SyntaxError: var-positional argument cannot have default value
@@ -543,39 +543,39 @@
543543
Traceback (most recent call last):
544544
SyntaxError: expected default value expression
545545
546-
>>> lambda /,a,b,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
546+
>>> lambda /,a,b,c: None
547547
Traceback (most recent call last):
548548
SyntaxError: at least one argument must precede /
549549
550-
>>> lambda a,/,/,b,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
550+
>>> lambda a,/,/,b,c: None
551551
Traceback (most recent call last):
552552
SyntaxError: / may appear only once
553553
554-
>>> lambda a,/,a1,/,b,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
554+
>>> lambda a,/,a1,/,b,c: None
555555
Traceback (most recent call last):
556556
SyntaxError: / may appear only once
557557
558-
>>> lambda a=1,/,/,*b,/,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
558+
>>> lambda a=1,/,/,*b,/,c: None
559559
Traceback (most recent call last):
560560
SyntaxError: / may appear only once
561561
562-
>>> lambda a,/,a1=1,/,b,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
562+
>>> lambda a,/,a1=1,/,b,c: None
563563
Traceback (most recent call last):
564564
SyntaxError: / may appear only once
565565
566-
>>> lambda a,*b,c,/,d,e: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
566+
>>> lambda a,*b,c,/,d,e: None
567567
Traceback (most recent call last):
568568
SyntaxError: / must be ahead of *
569569
570-
>>> lambda a=1,*b,c=3,/,d,e: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
570+
>>> lambda a=1,*b,c=3,/,d,e: None
571571
Traceback (most recent call last):
572572
SyntaxError: / must be ahead of *
573573
574574
>>> lambda a=1,/*,b,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
575575
Traceback (most recent call last):
576576
SyntaxError: expected comma between / and *
577577
578-
>>> lambda a,*b=3,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
578+
>>> lambda a,*b=3,c: None
579579
Traceback (most recent call last):
580580
SyntaxError: var-positional argument cannot have default value
581581
@@ -627,11 +627,11 @@
627627
Traceback (most recent call last):
628628
SyntaxError: expected default value expression
629629
630-
>>> lambda a,d=3,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
630+
>>> lambda a,d=3,c: None
631631
Traceback (most recent call last):
632632
SyntaxError: parameter without a default follows parameter with a default
633633
634-
>>> lambda a,/,d=3,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
634+
>>> lambda a,/,d=3,c: None
635635
Traceback (most recent call last):
636636
SyntaxError: parameter without a default follows parameter with a default
637637
@@ -661,25 +661,25 @@
661661
>>> L = range(10)
662662
>>> f(x for x in L)
663663
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
664-
>>> f(x for x in L, 1) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
664+
>>> f(x for x in L, 1)
665665
Traceback (most recent call last):
666666
SyntaxError: Generator expression must be parenthesized
667-
>>> f(x for x in L, y=1) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
667+
>>> f(x for x in L, y=1)
668668
Traceback (most recent call last):
669669
SyntaxError: Generator expression must be parenthesized
670-
>>> f(x for x in L, *[]) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
670+
>>> f(x for x in L, *[])
671671
Traceback (most recent call last):
672672
SyntaxError: Generator expression must be parenthesized
673-
>>> f(x for x in L, **{}) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
673+
>>> f(x for x in L, **{})
674674
Traceback (most recent call last):
675675
SyntaxError: Generator expression must be parenthesized
676-
>>> f(L, x for x in L) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
676+
>>> f(L, x for x in L)
677677
Traceback (most recent call last):
678678
SyntaxError: Generator expression must be parenthesized
679-
>>> f(x for x in L, y for y in L) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
679+
>>> f(x for x in L, y for y in L)
680680
Traceback (most recent call last):
681681
SyntaxError: Generator expression must be parenthesized
682-
>>> f(x for x in L,) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
682+
>>> f(x for x in L,)
683683
Traceback (most recent call last):
684684
SyntaxError: Generator expression must be parenthesized
685685
>>> f((x for x in L), 1)
@@ -1027,7 +1027,7 @@
10271027
SyntaxError: no binding for nonlocal 'x' found
10281028
10291029
From SF bug #1705365
1030-
>>> nonlocal x # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1030+
>>> nonlocal x
10311031
Traceback (most recent call last):
10321032
...
10331033
SyntaxError: nonlocal declaration not allowed at module level
@@ -1351,7 +1351,7 @@
13511351
13521352
Custom error messages for try blocks that are not followed by except/finally
13531353
1354-
>>> try: # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1354+
>>> try:
13551355
... x = 34
13561356
...
13571357
Traceback (most recent call last):
@@ -1705,14 +1705,14 @@
17051705
Check that an multiple exception types with missing parentheses
17061706
raise a custom exception only when using 'as'
17071707
1708-
>>> try: # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1708+
>>> try:
17091709
... pass
17101710
... except A, B, C as blech:
17111711
... pass
17121712
Traceback (most recent call last):
17131713
SyntaxError: multiple exception types must be parenthesized when using 'as'
17141714
1715-
>>> try: # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1715+
>>> try:
17161716
... pass
17171717
... except A, B, C as blech:
17181718
... pass
@@ -1722,14 +1722,14 @@
17221722
SyntaxError: multiple exception types must be parenthesized when using 'as'
17231723
17241724
1725-
>>> try: # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1725+
>>> try:
17261726
... pass
17271727
... except* A, B, C as blech:
17281728
... pass
17291729
Traceback (most recent call last):
17301730
SyntaxError: multiple exception types must be parenthesized when using 'as'
17311731
1732-
>>> try: # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1732+
>>> try:
17331733
... pass
17341734
... except* A, B, C as blech:
17351735
... pass
@@ -1880,7 +1880,7 @@
18801880
Traceback (most recent call last):
18811881
SyntaxError: invalid syntax. Did you mean 'in'?
18821882
1883-
>>> f(a=23, a=234) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
1883+
>>> f(a=23, a=234)
18841884
Traceback (most recent call last):
18851885
...
18861886
SyntaxError: keyword argument repeated: a
@@ -2001,11 +2001,11 @@
20012001
Traceback (most recent call last):
20022002
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
20032003
2004-
>>> from t import x, # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2004+
>>> from t import x,
20052005
Traceback (most recent call last):
20062006
SyntaxError: trailing comma not allowed without surrounding parentheses
20072007
2008-
>>> from t import x,y, # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2008+
>>> from t import x,y,
20092009
Traceback (most recent call last):
20102010
SyntaxError: trailing comma not allowed without surrounding parentheses
20112011
@@ -2164,31 +2164,31 @@
21642164
21652165
# 'not' after operators:
21662166
2167-
>>> 3 + not 3 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2167+
>>> 3 + not 3
21682168
Traceback (most recent call last):
21692169
SyntaxError: 'not' after an operator must be parenthesized
21702170
2171-
>>> 3 * not 3 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2171+
>>> 3 * not 3
21722172
Traceback (most recent call last):
21732173
SyntaxError: 'not' after an operator must be parenthesized
21742174
2175-
>>> + not 3 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2175+
>>> + not 3
21762176
Traceback (most recent call last):
21772177
SyntaxError: 'not' after an operator must be parenthesized
21782178
2179-
>>> - not 3 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2179+
>>> - not 3
21802180
Traceback (most recent call last):
21812181
SyntaxError: 'not' after an operator must be parenthesized
21822182
2183-
>>> ~ not 3 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2183+
>>> ~ not 3
21842184
Traceback (most recent call last):
21852185
SyntaxError: 'not' after an operator must be parenthesized
21862186
2187-
>>> 3 + - not 3 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2187+
>>> 3 + - not 3
21882188
Traceback (most recent call last):
21892189
SyntaxError: 'not' after an operator must be parenthesized
21902190
2191-
>>> 3 + not -1 # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2191+
>>> 3 + not -1
21922192
Traceback (most recent call last):
21932193
SyntaxError: 'not' after an operator must be parenthesized
21942194
@@ -2660,7 +2660,7 @@ def f(x: *b)
26602660
...
26612661
SyntaxError: yield expression cannot be used within the definition of a generic
26622662
2663-
>>> f(**x, *y) # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
2663+
>>> f(**x, *y)
26642664
Traceback (most recent call last):
26652665
SyntaxError: iterable argument unpacking follows keyword argument unpacking
26662666
@@ -2936,24 +2936,20 @@ def test_bad_outdent(self):
29362936
"unindent does not match .* level",
29372937
subclass=IndentationError)
29382938

2939-
@unittest.expectedFailure # TODO: RUSTPYTHON
29402939
def test_kwargs_last(self):
29412940
self._check_error("int(base=10, '2')",
29422941
"positional argument follows keyword argument")
29432942

2944-
@unittest.expectedFailure # TODO: RUSTPYTHON
29452943
def test_kwargs_last2(self):
29462944
self._check_error("int(**{'base': 10}, '2')",
29472945
"positional argument follows "
29482946
"keyword argument unpacking")
29492947

2950-
@unittest.expectedFailure # TODO: RUSTPYTHON
29512948
def test_kwargs_last3(self):
29522949
self._check_error("int(**{'base': 10}, *['2'])",
29532950
"iterable argument unpacking follows "
29542951
"keyword argument unpacking")
29552952

2956-
@unittest.expectedFailure # TODO: RUSTPYTHON
29572953
def test_generator_in_function_call(self):
29582954
self._check_error("foo(x, y for y in range(3) for z in range(2) if z , p)",
29592955
"Generator expression must be parenthesized",
@@ -3126,7 +3122,6 @@ def test_invalid_line_continuation_error_position(self):
31263122
"unexpected character after line continuation character",
31273123
lineno=3, offset=4)
31283124

3129-
@unittest.expectedFailure # TODO: RUSTPYTHON
31303125
def test_invalid_line_continuation_left_recursive(self):
31313126
# Check bpo-42218: SyntaxErrors following left-recursive rules
31323127
# (t_primary_raw in this case) need to be tested explicitly
@@ -3198,7 +3193,6 @@ def case(x):
31983193
"""
31993194
compile(code, "<string>", "exec")
32003195

3201-
@unittest.expectedFailure # TODO: RUSTPYTHON
32023196
def test_multiline_compiler_error_points_to_the_end(self):
32033197
self._check_error(
32043198
"call(\na=1,\na=1\n)",
Collapse file

‎crates/codegen/src/symboltable.rs‎

Copy file name to clipboardExpand all lines: crates/codegen/src/symboltable.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2941,7 +2941,7 @@ impl SymbolTableBuilder {
29412941
match role {
29422942
SymbolUsage::Nonlocal if scope_depth < 2 => {
29432943
return Err(SymbolTableError {
2944-
error: format!("cannot define nonlocal '{name}' at top level."),
2944+
error: "nonlocal declaration not allowed at module level".into(),
29452945
location,
29462946
});
29472947
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.