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