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)
| 882 | /// this case will break any internal state that depends on function scopes, such as `async` |
| 883 | /// context detection. |
| 884 | pub fn visit_stmt<Ctx: SemanticSyntaxContext>(&mut self, stmt: &ast::Stmt, ctx: &Ctx) { |
| 885 | // check for errors |
| 886 | self.check_stmt(stmt, ctx); |
| 887 | |
| 888 | // update internal state |
| 889 | self.augmented_assignment_target = None; |
| 890 | |
| 891 | match stmt { |
| 892 | Stmt::Expr(StmtExpr { value, .. }) |
| 893 | if !self.seen_module_docstring_boundary && value.is_string_literal_expr() => {} |
| 894 | Stmt::ImportFrom(import_from) => { |
| 895 | // Allow eager `__future__` imports until we see any other import. Lazy imports, |
| 896 | // including `lazy from __future__ import ...`, always close the boundary. |
| 897 | if import_from.is_lazy || !import_from.is_future_import(ctx.python_version()) { |
| 898 | self.seen_futures_boundary = true; |
| 899 | } |
| 900 | } |
| 901 | Stmt::FunctionDef(StmtFunctionDef { is_async, body, .. }) => { |
| 902 | if *is_async { |
| 903 | let mut visitor = ReturnVisitor::default(); |
| 904 | visitor.visit_body(body); |
| 905 | |
| 906 | if visitor.has_yield { |
| 907 | if let Some(return_range) = visitor.return_range { |
| 908 | Self::add_error( |
| 909 | ctx, |
| 910 | SemanticSyntaxErrorKind::ReturnInGenerator, |
| 911 | return_range, |
| 912 | ); |
| 913 | } |
| 914 | } |
| 915 | } |
| 916 | self.seen_futures_boundary = true; |
| 917 | } |
| 918 | Stmt::AugAssign(ast::StmtAugAssign { target, .. }) => { |
| 919 | self.augmented_assignment_target = Some(target.range()); |
| 920 | self.seen_futures_boundary = true; |
| 921 | } |
| 922 | _ => { |
| 923 | self.seen_futures_boundary = true; |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | self.seen_module_docstring_boundary = true; |
| 928 | } |
| 929 | |
| 930 | /// Check `expr` for semantic syntax errors and update the checker's internal state. |
| 931 | pub fn visit_expr<Ctx: SemanticSyntaxContext>(&mut self, expr: &Expr, ctx: &Ctx) { |
nothing calls this directly
no test coverage detected