From e9941cd71459a75ee556422b37a192bf681ed425 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 5 Dec 2024 18:06:20 +0530 Subject: [PATCH] [red-knot] Move standalone expr inference to `for` non-name target (#14788) ## Summary Ref: https://github.com/astral-sh/ruff/pull/14754#discussion_r1871040646 ## Test Plan Remove the TODO comment and update the mdtest. --- .../resources/mdtest/invalid_syntax.md | 5 ----- crates/red_knot_python_semantic/src/types/infer.rs | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/crates/red_knot_python_semantic/resources/mdtest/invalid_syntax.md b/crates/red_knot_python_semantic/resources/mdtest/invalid_syntax.md index 2363257e7e..e33b7cb819 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/invalid_syntax.md +++ b/crates/red_knot_python_semantic/resources/mdtest/invalid_syntax.md @@ -26,13 +26,10 @@ def True(for): # error: [invalid-syntax] pass -# TODO: Why is there two diagnostics for the same error? - # error: [invalid-syntax] # error: [invalid-syntax] # error: [invalid-syntax] # error: [unresolved-reference] "Name `pass` used when not defined" -# error: [unresolved-reference] "Name `pass` used when not defined" for while in pass: pass @@ -58,12 +55,10 @@ match while: ### Attribute expression ```py -# TODO: Why is there two diagnostics for the same error? # TODO: Check when support for attribute expressions is added # error: [invalid-syntax] # error: [unresolved-reference] "Name `foo` used when not defined" -# error: [unresolved-reference] "Name `foo` used when not defined" for x in foo.pass: pass ``` diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 2173e0edf6..afdd60e829 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -1900,12 +1900,11 @@ impl<'db> TypeInferenceBuilder<'db> { is_async: _, } = for_statement; - self.infer_standalone_expression(iter); - // TODO more complex assignment targets if let ast::Expr::Name(name) = &**target { self.infer_definition(name); } else { + self.infer_standalone_expression(iter); self.infer_expression(target); } self.infer_body(body);