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

Method visit_expr

crates/ruff_python_parser/src/semantic_errors.rs:931–1124  ·  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

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) {
932 match expr {
933 Expr::ListComp(ast::ExprListComp {
934 elt, generators, ..
935 })
936 | Expr::SetComp(ast::ExprSetComp {
937 elt, generators, ..
938 }) => {
939 Self::check_generator_expr(elt, generators, ctx);
940 Self::check_generator_clauses(generators, ctx);
941 Self::async_comprehension_in_sync_comprehension(ctx, generators);
942 for generator in generators.iter().filter(|g| g.is_async) {
943 Self::await_outside_async_function(
944 ctx,
945 generator,
946 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
947 );
948 }
949 }
950 Expr::DictComp(ast::ExprDictComp {
951 key,
952 value,
953 generators,
954 ..
955 }) => {
956 if let Some(key) = key {
957 Self::check_generator_expr(key, generators, ctx);
958 }
959 Self::check_generator_expr(value, generators, ctx);
960 Self::check_generator_clauses(generators, ctx);
961 Self::async_comprehension_in_sync_comprehension(ctx, generators);
962 for generator in generators.iter().filter(|g| g.is_async) {
963 Self::await_outside_async_function(
964 ctx,
965 generator,
966 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
967 );
968 }
969 }
970 Expr::Generator(ast::ExprGenerator {
971 elt, generators, ..
972 }) => {
973 Self::check_generator_expr(elt, generators, ctx);
974 Self::check_generator_clauses(generators, ctx);
975 // Note that `await_outside_async_function` is not called here because generators
976 // are evaluated lazily. See the note in the function for more details.
977 }
978 Expr::Name(ast::ExprName {
979 range,
980 id,
981 ctx: expr_ctx,
982 node_index: _,
983 }) => {
984 // test_err write_to_debug_expr
985 // del __debug__
986 // del x, y, __debug__, z
987 // __debug__ = 1
988 // 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