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

Method visit_expr

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

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) {
915 match expr {
916 Expr::ListComp(ast::ExprListComp {
917 elt, generators, ..
918 })
919 | Expr::SetComp(ast::ExprSetComp {
920 elt, generators, ..
921 }) => {
922 Self::check_generator_expr(elt, generators, ctx);
923 Self::check_generator_clauses(generators, ctx);
924 Self::async_comprehension_in_sync_comprehension(ctx, generators);
925 for generator in generators.iter().filter(|g| g.is_async) {
926 Self::await_outside_async_function(
927 ctx,
928 generator,
929 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
930 );
931 }
932 }
933 Expr::DictComp(ast::ExprDictComp {
934 key,
935 value,
936 generators,
937 ..
938 }) => {
939 if let Some(key) = key {
940 Self::check_generator_expr(key, generators, ctx);
941 }
942 Self::check_generator_expr(value, generators, ctx);
943 Self::check_generator_clauses(generators, ctx);
944 Self::async_comprehension_in_sync_comprehension(ctx, generators);
945 for generator in generators.iter().filter(|g| g.is_async) {
946 Self::await_outside_async_function(
947 ctx,
948 generator,
949 AwaitOutsideAsyncFunctionKind::AsyncComprehension,
950 );
951 }
952 }
953 Expr::Generator(ast::ExprGenerator {
954 elt, generators, ..
955 }) => {
956 Self::check_generator_expr(elt, generators, ctx);
957 Self::check_generator_clauses(generators, ctx);
958 // Note that `await_outside_async_function` is not called here because generators
959 // are evaluated lazily. See the note in the function for more details.
960 }
961 Expr::Name(ast::ExprName {
962 range,
963 id,
964 ctx: expr_ctx,
965 node_index: _,
966 }) => {
967 // test_err write_to_debug_expr
968 // del __debug__
969 // del x, y, __debug__, z
970 // __debug__ = 1
971 // 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