[syntax-errors] type alias statements before Python 3.12 (#16478)
Summary -- Another simple one, just detect standalone `type` statements. I limited the diagnostic to `type` itself like [pyright]. That probably makes the most sense for more complicated examples. Test Plan -- Inline tests. [pyright]: https://pyright-play.net/?pythonVersion=3.8&strict=true&code=C4TwDgpgBAHlC8UCWA7YQ
This commit is contained in:
@@ -888,8 +888,22 @@ impl<'src> Parser<'src> {
|
||||
/// See: <https://docs.python.org/3/reference/simple_stmts.html#the-type-statement>
|
||||
fn parse_type_alias_statement(&mut self) -> ast::StmtTypeAlias {
|
||||
let start = self.node_start();
|
||||
let type_range = self.current_token_range();
|
||||
self.bump(TokenKind::Type);
|
||||
|
||||
// test_ok type_stmt_py312
|
||||
// # parse_options: {"target-version": "3.12"}
|
||||
// type x = int
|
||||
|
||||
// test_err type_stmt_py311
|
||||
// # parse_options: {"target-version": "3.11"}
|
||||
// type x = int
|
||||
|
||||
self.add_unsupported_syntax_error(
|
||||
UnsupportedSyntaxErrorKind::TypeAliasStatement,
|
||||
type_range,
|
||||
);
|
||||
|
||||
let mut name = Expr::Name(self.parse_name());
|
||||
helpers::set_expr_ctx(&mut name, ExprContext::Store);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user