mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-08 12:48:41 +00:00
[syntax-errors] Check annotations in annotated assignments (#17283)
Summary -- This PR extends the checks in #17101 and #17282 to annotated assignments after Python 3.13. Currently stacked on #17282 to include `await`. Test Plan -- New inline tests. These are simpler than the other cases because there's no place to put generics.
This commit is contained in:
parent
127a45622f
commit
0891689d2f
5 changed files with 433 additions and 0 deletions
|
@ -119,6 +119,32 @@ impl SemanticSyntaxChecker {
|
|||
|
||||
fn check_annotation<Ctx: SemanticSyntaxContext>(stmt: &ast::Stmt, ctx: &Ctx) {
|
||||
match stmt {
|
||||
Stmt::AnnAssign(ast::StmtAnnAssign { annotation, .. }) => {
|
||||
if ctx.python_version() > PythonVersion::PY313 {
|
||||
// test_ok valid_annotation_py313
|
||||
// # parse_options: {"target-version": "3.13"}
|
||||
// a: (x := 1)
|
||||
// def outer():
|
||||
// b: (yield 1)
|
||||
// c: (yield from 1)
|
||||
// async def outer():
|
||||
// d: (await 1)
|
||||
|
||||
// test_err invalid_annotation_py314
|
||||
// # parse_options: {"target-version": "3.14"}
|
||||
// a: (x := 1)
|
||||
// def outer():
|
||||
// b: (yield 1)
|
||||
// c: (yield from 1)
|
||||
// async def outer():
|
||||
// d: (await 1)
|
||||
let mut visitor = InvalidExpressionVisitor {
|
||||
position: InvalidExpressionPosition::TypeAnnotation,
|
||||
ctx,
|
||||
};
|
||||
visitor.visit_expr(annotation);
|
||||
}
|
||||
}
|
||||
Stmt::FunctionDef(ast::StmtFunctionDef {
|
||||
type_params,
|
||||
parameters,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue