Skip to content

Commit

Permalink
[red-knot] Move standalone expr inference to for non-name target (#…
Browse files Browse the repository at this point in the history
…14788)

## Summary

Ref: #14754 (comment)

## Test Plan

Remove the TODO comment and update the mdtest.
  • Loading branch information
dhruvmanila authored Dec 5, 2024
1 parent 43bf1a8 commit e9941cd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
```
3 changes: 1 addition & 2 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e9941cd

Please sign in to comment.