Skip to content

Commit

Permalink
Fix panic when filling up types vector during unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Oct 30, 2024
1 parent c6b8215 commit e44f117
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/red_knot_python_semantic/resources/mdtest/unpacking.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ reveal_type(b) # revealed: Literal[2]
reveal_type(c) # revealed: @Todo
```

### Starred expression (6)

```py
# TODO: Remove 'not-iterable' diagnostic
# TODO: Add diagnostic (need more values to unpack)
(a, b, c, *d, e, f) = (1,) # error: "Object of type `None` is not iterable"
reveal_type(a) # revealed: Literal[1]
reveal_type(b) # revealed: Unknown
reveal_type(c) # revealed: Unknown
reveal_type(d) # revealed: @Todo
reveal_type(e) # revealed: Unknown
reveal_type(f) # revealed: Unknown
```

### Non-iterable unpacking

TODO: Remove duplicate diagnostics. This is happening because for a sequence-like
Expand Down
2 changes: 2 additions & 0 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ impl<'db> TypeInferenceBuilder<'db> {
Cow::Owned(element_types)
} else {
let mut element_types = tuple_ty.elements(builder.db).to_vec();
element_types.resize(elts.len(), Type::Unknown);
// TODO: This should be `list[Unknown]`
element_types.insert(starred_index, Type::Todo);
Cow::Owned(element_types)
}
Expand Down

0 comments on commit e44f117

Please sign in to comment.