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