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

Method visit_expr

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

921
922 /// Check `expr` for semantic syntax errors and update the checker's internal state.
923 pub fn visit_expr<Ctx: SemanticSyntaxContext>(&mut self, expr: &Expr, ctx: &Ctx) {
924 match expr {
925 Expr::ListComp(ast::ExprListComp {
926 elt, generators, ..
927 })
928 | Expr::SetComp(ast::ExprSetComp {
929 elt, generators, ..
930 }) => {
931 Self::check_generator_expr(elt, generators, ctx);
932 Self::check_generator_clauses(generators, ctx);
933 Self::async_comprehension_in_sync_comprehension(ctx, generators);
934 for generator in generators.iter().filter(|g| g.is_async) {
935 Self::await_outside_async_function(
936 ctx,
937 generator,
938 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
939 );
940 }
941 }
942 Expr::DictComp(ast::ExprDictComp {
943 key,
944 value,
945 generators,
946 ..
947 }) => {
948 if let Some(key) = key {
949 Self::check_generator_expr(key, generators, ctx);
950 }
951 Self::check_generator_expr(value, generators, ctx);
952 Self::check_generator_clauses(generators, ctx);
953 Self::async_comprehension_in_sync_comprehension(ctx, generators);
954 for generator in generators.iter().filter(|g| g.is_async) {
955 Self::await_outside_async_function(
956 ctx,
957 generator,
958 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
959 );
960 }
961 }
962 Expr::Generator(ast::ExprGenerator {
963 elt, generators, ..
964 }) => {
965 Self::check_generator_expr(elt, generators, ctx);
966 Self::check_generator_clauses(generators, ctx);
967 // Note that `await_outside_async_function` is not called here because generators
968 // are evaluated lazily. See the note in the function for more details.
969 }
970 Expr::Name(ast::ExprName {
971 range,
972 id,
973 ctx: expr_ctx,
974 node_index: _,
975 }) => {
976 // test_err write_to_debug_expr
977 // del __debug__
978 // del x, y, __debug__, z
979 // __debug__ = 1
980 // 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