MCPcopy Create free account
hub / github.com/astral-sh/ruff / visit_expr

Method visit_expr

crates/ruff_python_parser/src/semantic_errors.rs:865–1023  ·  view source on GitHub ↗

Check `expr` for semantic syntax errors and update the checker's internal state.

(&mut self, expr: &Expr, ctx: &Ctx)

Source from the content-addressed store, hash-verified

863
864 /// Check `expr` for semantic syntax errors and update the checker's internal state.
865 pub fn visit_expr<Ctx: SemanticSyntaxContext>(&mut self, expr: &Expr, ctx: &Ctx) {
866 match expr {
867 Expr::ListComp(ast::ExprListComp {
868 elt, generators, ..
869 })
870 | Expr::SetComp(ast::ExprSetComp {
871 elt, generators, ..
872 }) => {
873 Self::check_generator_expr(elt, generators, ctx);
874 Self::check_generator_clauses(generators, ctx);
875 Self::async_comprehension_in_sync_comprehension(ctx, generators);
876 for generator in generators.iter().filter(|g| g.is_async) {
877 Self::await_outside_async_function(
878 ctx,
879 generator,
880 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
881 );
882 }
883 }
884 Expr::DictComp(ast::ExprDictComp {
885 key,
886 value,
887 generators,
888 ..
889 }) => {
890 if let Some(key) = key {
891 Self::check_generator_expr(key, generators, ctx);
892 }
893 Self::check_generator_expr(value, generators, ctx);
894 Self::check_generator_clauses(generators, ctx);
895 Self::async_comprehension_in_sync_comprehension(ctx, generators);
896 for generator in generators.iter().filter(|g| g.is_async) {
897 Self::await_outside_async_function(
898 ctx,
899 generator,
900 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
901 );
902 }
903 }
904 Expr::Generator(ast::ExprGenerator {
905 elt, generators, ..
906 }) => {
907 Self::check_generator_expr(elt, generators, ctx);
908 Self::check_generator_clauses(generators, ctx);
909 // Note that `await_outside_async_function` is not called here because generators
910 // are evaluated lazily. See the note in the function for more details.
911 }
912 Expr::Name(ast::ExprName {
913 range,
914 id,
915 ctx: expr_ctx,
916 node_index: _,
917 }) => {
918 // test_err write_to_debug_expr
919 // del __debug__
920 // del x, y, __debug__, z
921 // __debug__ = 1
922 // x, y, __debug__, z = 1, 2, 3, 4

Callers 6

check_annotationMethod · 0.45
check_class_body_exprMethod · 0.45
visit_type_paramMethod · 0.45

Calls 15

is_name_exprMethod · 0.80
walk_exprFunction · 0.50
filterMethod · 0.45
iterMethod · 0.45
python_versionMethod · 0.45
globalMethod · 0.45
startMethod · 0.45
to_stringMethod · 0.45
rangeMethod · 0.45
in_function_scopeMethod · 0.45
in_async_contextMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected