(stmt: &ast::Stmt, ctx: &Ctx)
| 376 | } |
| 377 | |
| 378 | fn check_annotation<Ctx: SemanticSyntaxContext>(stmt: &ast::Stmt, ctx: &Ctx) { |
| 379 | match stmt { |
| 380 | Stmt::AnnAssign(ast::StmtAnnAssign { |
| 381 | target, annotation, .. |
| 382 | }) => { |
| 383 | if ctx.python_version() > PythonVersion::PY313 { |
| 384 | // test_ok valid_annotation_py313 |
| 385 | // # parse_options: {"target-version": "3.13"} |
| 386 | // a: (x := 1) |
| 387 | // def outer(): |
| 388 | // b: (yield 1) |
| 389 | // c: (yield from 1) |
| 390 | // async def outer(): |
| 391 | // d: (await 1) |
| 392 | |
| 393 | // test_err invalid_annotation_py314 |
| 394 | // # parse_options: {"target-version": "3.14"} |
| 395 | // a: (x := 1) |
| 396 | // def outer(): |
| 397 | // b: (yield 1) |
| 398 | // c: (yield from 1) |
| 399 | // async def outer(): |
| 400 | // d: (await 1) |
| 401 | let mut visitor = InvalidExpressionVisitor { |
| 402 | position: InvalidExpressionPosition::TypeAnnotation, |
| 403 | ctx, |
| 404 | }; |
| 405 | visitor.visit_expr(annotation); |
| 406 | } |
| 407 | if let Expr::Name(ast::ExprName { id, .. }) = target.as_ref() { |
| 408 | if let Some(global_stmt) = ctx.global(id.as_str()) { |
| 409 | let global_start = global_stmt.start(); |
| 410 | if !ctx.in_module_scope() || target.start() < global_start { |
| 411 | Self::add_error( |
| 412 | ctx, |
| 413 | SemanticSyntaxErrorKind::AnnotatedGlobal(id.to_string()), |
| 414 | target.range(), |
| 415 | ); |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | Stmt::FunctionDef(ast::StmtFunctionDef { |
| 421 | type_params, |
| 422 | parameters, |
| 423 | returns, |
| 424 | .. |
| 425 | }) => { |
| 426 | // test_ok valid_annotation_function_py313 |
| 427 | // # parse_options: {"target-version": "3.13"} |
| 428 | // def f() -> (y := 3): ... |
| 429 | // def g(arg: (x := 1)): ... |
| 430 | // def outer(): |
| 431 | // def i(x: (yield 1)): ... |
| 432 | // def k() -> (yield 1): ... |
| 433 | // def m(x: (yield from 1)): ... |
| 434 | // def o() -> (yield from 1): ... |
| 435 | // async def outer(): |
nothing calls this directly
no test coverage detected