Check `stmt` for semantic syntax errors and update the checker's internal state. Note that this method should only be called when traversing `stmt` *and* its children. For example, if traversal of function bodies needs to be deferred, avoid calling `visit_stmt` on the function itself until the deferred body is visited too. Failing to defer `visit_stmt` in this case will break any internal state t
(&mut self, stmt: &ast::Stmt, ctx: &Ctx)
| 869 | /// this case will break any internal state that depends on function scopes, such as `async` |
| 870 | /// context detection. |
| 871 | pub fn visit_stmt<Ctx: SemanticSyntaxContext>(&mut self, stmt: &ast::Stmt, ctx: &Ctx) { |
| 872 | // check for errors |
| 873 | self.check_stmt(stmt, ctx); |
| 874 | |
| 875 | // update internal state |
| 876 | match stmt { |
| 877 | Stmt::Expr(StmtExpr { value, .. }) |
| 878 | if !self.seen_module_docstring_boundary && value.is_string_literal_expr() => {} |
| 879 | Stmt::ImportFrom(StmtImportFrom { |
| 880 | module, is_lazy, .. |
| 881 | }) => { |
| 882 | // Allow eager `__future__` imports until we see any other import. Lazy imports, |
| 883 | // including `lazy from __future__ import ...`, always close the boundary. |
| 884 | if *is_lazy || !matches!(module.as_deref(), Some("__future__")) { |
| 885 | self.seen_futures_boundary = true; |
| 886 | } |
| 887 | } |
| 888 | Stmt::FunctionDef(StmtFunctionDef { is_async, body, .. }) => { |
| 889 | if *is_async { |
| 890 | let mut visitor = ReturnVisitor::default(); |
| 891 | visitor.visit_body(body); |
| 892 | |
| 893 | if visitor.has_yield { |
| 894 | if let Some(return_range) = visitor.return_range { |
| 895 | Self::add_error( |
| 896 | ctx, |
| 897 | SemanticSyntaxErrorKind::ReturnInGenerator, |
| 898 | return_range, |
| 899 | ); |
| 900 | } |
| 901 | } |
| 902 | } |
| 903 | self.seen_futures_boundary = true; |
| 904 | } |
| 905 | _ => { |
| 906 | self.seen_futures_boundary = true; |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | self.seen_module_docstring_boundary = true; |
| 911 | } |
| 912 | |
| 913 | /// Check `expr` for semantic syntax errors and update the checker's internal state. |
| 914 | pub fn visit_expr<Ctx: SemanticSyntaxContext>(&mut self, expr: &Expr, ctx: &Ctx) { |
nothing calls this directly
no test coverage detected