Make syntax error for unparenthesized except tuples version specific to before 3.14 (#17660)

What it says on the tin 😄
This commit is contained in:
Dylan 2025-04-29 07:55:30 -05:00 committed by GitHub
parent 31e6576971
commit 3c460a7b9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 526 additions and 274 deletions

View file

@ -1581,25 +1581,50 @@ impl<'src> Parser<'src> {
..
})
) {
// test_err except_stmt_unparenthesized_tuple
// try:
// pass
// except x, y:
// pass
// except x, y as exc:
// pass
// try:
// pass
// except* x, y:
// pass
// except* x, y as eg:
// pass
self.add_error(
ParseErrorType::OtherError(
"Multiple exception types must be parenthesized".to_string(),
),
&parsed_expr,
);
if self.at(TokenKind::As) {
// test_err except_stmt_unparenthesized_tuple_as
// try:
// pass
// except x, y as exc:
// pass
// try:
// pass
// except* x, y as eg:
// pass
self.add_error(
ParseErrorType::OtherError(
"Multiple exception types must be parenthesized when using `as`"
.to_string(),
),
&parsed_expr,
);
} else {
// test_err except_stmt_unparenthesized_tuple_no_as_py313
// # parse_options: {"target-version": "3.13"}
// try:
// pass
// except x, y:
// pass
// try:
// pass
// except* x, y:
// pass
// test_ok except_stmt_unparenthesized_tuple_no_as_py314
// # parse_options: {"target-version": "3.14"}
// try:
// pass
// except x, y:
// pass
// try:
// pass
// except* x, y:
// pass
self.add_unsupported_syntax_error(
UnsupportedSyntaxErrorKind::UnparenthesizedExceptionTypes,
parsed_expr.range(),
);
}
}
Some(Box::new(parsed_expr.expr))
} else {