Skip to content

Commit f3abe06

Browse files
committed
Align more error messages with CPython 3.14.5
1 parent ae3804f commit f3abe06

2 files changed

Lines changed: 45 additions & 21 deletions

File tree

‎Lib/test/test_syntax.py‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -478,47 +478,47 @@
478478
Traceback (most recent call last):
479479
SyntaxError: var-keyword argument cannot have default value
480480
481-
>>> def foo(a,*a, b, **c, d): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
481+
>>> def foo(a,*a, b, **c, d):
482482
... pass
483483
Traceback (most recent call last):
484484
SyntaxError: arguments cannot follow var-keyword argument
485485
486-
>>> def foo(a,*a, b, **c, d=4): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
486+
>>> def foo(a,*a, b, **c, d=4):
487487
... pass
488488
Traceback (most recent call last):
489489
SyntaxError: arguments cannot follow var-keyword argument
490490
491-
>>> def foo(a,*a, b, **c, *d): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
491+
>>> def foo(a,*a, b, **c, *d):
492492
... pass
493493
Traceback (most recent call last):
494494
SyntaxError: arguments cannot follow var-keyword argument
495495
496-
>>> def foo(a,*a, b, **c, **d): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
496+
>>> def foo(a,*a, b, **c, **d):
497497
... pass
498498
Traceback (most recent call last):
499499
SyntaxError: arguments cannot follow var-keyword argument
500500
501-
>>> def foo(a=1,/,**b,/,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
501+
>>> def foo(a=1,/,**b,/,c):
502502
... pass
503503
Traceback (most recent call last):
504504
SyntaxError: arguments cannot follow var-keyword argument
505505
506-
>>> def foo(*b,*d): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
506+
>>> def foo(*b,*d):
507507
... pass
508508
Traceback (most recent call last):
509509
SyntaxError: * argument may appear only once
510510
511-
>>> def foo(a,*b,c,*d,*e,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
511+
>>> def foo(a,*b,c,*d,*e,c):
512512
... pass
513513
Traceback (most recent call last):
514514
SyntaxError: * argument may appear only once
515515
516-
>>> def foo(a,b,/,c,*b,c,*d,*e,c): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
516+
>>> def foo(a,b,/,c,*b,c,*d,*e,c):
517517
... pass
518518
Traceback (most recent call last):
519519
SyntaxError: * argument may appear only once
520520
521-
>>> def foo(a,b,/,c,*b,c,*d,**e): # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
521+
>>> def foo(a,b,/,c,*b,c,*d,**e):
522522
... pass
523523
Traceback (most recent call last):
524524
SyntaxError: * argument may appear only once
@@ -583,39 +583,39 @@
583583
Traceback (most recent call last):
584584
SyntaxError: var-keyword argument cannot have default value
585585
586-
>>> lambda a, *a, b, **c, d: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
586+
>>> lambda a, *a, b, **c, d: None
587587
Traceback (most recent call last):
588588
SyntaxError: arguments cannot follow var-keyword argument
589589
590-
>>> lambda a,*a, b, **c, d=4: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
590+
>>> lambda a,*a, b, **c, d=4: None
591591
Traceback (most recent call last):
592592
SyntaxError: arguments cannot follow var-keyword argument
593593
594-
>>> lambda a,*a, b, **c, *d: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
594+
>>> lambda a,*a, b, **c, *d: None
595595
Traceback (most recent call last):
596596
SyntaxError: arguments cannot follow var-keyword argument
597597
598-
>>> lambda a,*a, b, **c, **d: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
598+
>>> lambda a,*a, b, **c, **d: None
599599
Traceback (most recent call last):
600600
SyntaxError: arguments cannot follow var-keyword argument
601601
602-
>>> lambda a=1,/,**b,/,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
602+
>>> lambda a=1,/,**b,/,c: None
603603
Traceback (most recent call last):
604604
SyntaxError: arguments cannot follow var-keyword argument
605605
606-
>>> lambda *b,*d: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
606+
>>> lambda *b,*d: None
607607
Traceback (most recent call last):
608608
SyntaxError: * argument may appear only once
609609
610-
>>> lambda a,*b,c,*d,*e,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
610+
>>> lambda a,*b,c,*d,*e,c: None
611611
Traceback (most recent call last):
612612
SyntaxError: * argument may appear only once
613613
614-
>>> lambda a,b,/,c,*b,c,*d,*e,c: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
614+
>>> lambda a,b,/,c,*b,c,*d,*e,c: None
615615
Traceback (most recent call last):
616616
SyntaxError: * argument may appear only once
617617
618-
>>> lambda a,b,/,c,*b,c,*d,**e: None # TODO: RUSTPYTHON; Wrong error message # doctest: +EXPECTED_FAILURE
618+
>>> lambda a,b,/,c,*b,c,*d,**e: None
619619
Traceback (most recent call last):
620620
SyntaxError: * argument may appear only once
621621

‎crates/vm/src/vm/vm_new.rs‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ impl SyntaxErrorInfo {
6161

6262
#[cfg(feature = "parser")]
6363
fn analyze_compile_error(&mut self, compile_error: &CompileError) {
64-
let CompileError::Parse(ParseError { error, .. }) = compile_error else {
64+
let CompileError::Parse(ParseError {
65+
error, location, ..
66+
}) = compile_error
67+
else {
6568
return;
6669
};
6770

@@ -104,7 +107,10 @@ impl SyntaxErrorInfo {
104107
}
105108

106109
ParseErrorType::Lexical(LexicalErrorType::UnclosedStringError) => {
107-
"unterminated string literal".into()
110+
format!(
111+
"unterminated string literal (detected at line {})",
112+
location.line
113+
)
108114
}
109115

110116
ParseErrorType::EmptyTypeParams => "Type parameter list cannot be empty".into(),
@@ -146,6 +152,10 @@ impl SyntaxErrorInfo {
146152
"iterable argument unpacking follows keyword argument unpacking".into()
147153
}
148154

155+
ParseErrorType::ParamAfterVarKeywordParam => {
156+
"arguments cannot follow var-keyword argument".into()
157+
}
158+
149159
ParseErrorType::OtherError(s)
150160
if s.eq_ignore_ascii_case(
151161
"bytes literal cannot be mixed with non-bytes literals",
@@ -207,11 +217,25 @@ impl SyntaxErrorInfo {
207217
}
208218

209219
ParseErrorType::OtherError(s)
210-
if s.eq_ignore_ascii_case("Expected `except` or `finally` after `try` block") =>
220+
if s.eq_ignore_ascii_case("expected `except` or `finally` after `try` block") =>
211221
{
212222
"expected 'except' or 'finally' block".into()
213223
}
214224

225+
ParseErrorType::OtherError(s)
226+
if s.eq_ignore_ascii_case("only one '*' parameter allowed") =>
227+
{
228+
"* argument may appear only once".into()
229+
}
230+
231+
ParseErrorType::OtherError(s)
232+
if s.eq_ignore_ascii_case(
233+
r#"cannot have both 'except' and 'except*' on the same 'try'"#,
234+
) =>
235+
{
236+
r#"cannot have both 'except' and 'except*' on the same 'try'"#.into()
237+
}
238+
215239
_ => return,
216240
};
217241

0 commit comments

Comments
 (0)