[syntax-errors] except* before Python 3.11 (#16446)

Summary
--

One of the simpler ones, just detect the use of `except*` before 3.11.

Test Plan
--

New inline tests.
This commit is contained in:
Brent Westbrook 2025-03-02 13:20:18 -05:00 committed by GitHub
parent 0d615b8765
commit e924ecbdac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 180 additions and 23 deletions

View file

@ -5,8 +5,7 @@ use rustc_hash::{FxBuildHasher, FxHashSet};
use ruff_python_ast::name::Name;
use ruff_python_ast::{
self as ast, ExceptHandler, Expr, ExprContext, IpyEscapeKind, Operator, PythonVersion, Stmt,
WithItem,
self as ast, ExceptHandler, Expr, ExprContext, IpyEscapeKind, Operator, Stmt, WithItem,
};
use ruff_text_size::{Ranged, TextSize};
@ -1458,13 +1457,28 @@ impl<'src> Parser<'src> {
);
}
// test_ok except_star_py311
// # parse_options: {"target-version": "3.11"}
// try: ...
// except* ValueError: ...
// test_err except_star_py310
// # parse_options: {"target-version": "3.10"}
// try: ...
// except* ValueError: ...
let range = self.node_range(try_start);
if is_star {
self.add_unsupported_syntax_error(UnsupportedSyntaxErrorKind::ExceptStar, range);
}
ast::StmtTry {
body: try_body,
handlers,
orelse,
finalbody,
is_star,
range: self.node_range(try_start),
range,
}
}
@ -2277,9 +2291,7 @@ impl<'src> Parser<'src> {
// case 1:
// pass
if self.options.target_version < PythonVersion::PY310 {
self.add_unsupported_syntax_error(UnsupportedSyntaxErrorKind::Match, match_range);
}
self.add_unsupported_syntax_error(UnsupportedSyntaxErrorKind::Match, match_range);
ast::StmtMatch {
subject: Box::new(subject),