Skip to content

Commit 260c2ec

Browse files
carljmAlexWaygood
andauthored
[red-knot] visit with-item vars even if not a Name (#13409)
This fixes the last panic on checking pandas. (Match statement became an `if let` because clippy decided it wanted that once I added the additional line in the else case?) --------- Co-authored-by: Alex Waygood <[email protected]>
1 parent f110d80 commit 260c2ec

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -926,14 +926,13 @@ impl<'db> TypeInferenceBuilder<'db> {
926926
} = with_statement;
927927

928928
for item in items {
929-
match item.optional_vars.as_deref() {
930-
Some(ast::Expr::Name(name)) => {
931-
self.infer_definition(name);
932-
}
933-
_ => {
934-
// TODO infer definitions in unpacking assignment
935-
self.infer_expression(&item.context_expr);
936-
}
929+
let target = item.optional_vars.as_deref();
930+
if let Some(ast::Expr::Name(name)) = target {
931+
self.infer_definition(name);
932+
} else {
933+
// TODO infer definitions in unpacking assignment
934+
self.infer_expression(&item.context_expr);
935+
self.infer_optional_expression(target);
937936
}
938937
}
939938

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
with foo() as self.bar:
2+
pass

0 commit comments

Comments
 (0)