mirror of
https://github.com/astral-sh/ruff.git
synced 2026-11-21 12:16:15 +08:00
## Summary
Python assigns unpacking targets from left to right. By the time it
tries to unpack `pair` below, `value` already holds `"bad"`.
```python
def f(pair: tuple[int, ...]) -> None:
value: int | str = 1
try:
value, (a, b) = "bad", pair
except ValueError:
value.bit_length() # Raises AttributeError when pair has the wrong length.
```
ty accepted this call because it took a checkpoint only before the outer
unpack, when `value` was still `1`. We now take a checkpoint before
unpacking each tuple or list target. The handler sees `Literal[1,
"bad"]`, so ty flags the call.
We also take the nested checkpoint when the source is an exact-length
literal. If we replace `pair` with `(1, 2)`, the unpack always succeeds,
but ty can still include `"bad"` in the handler even if a later
assignment overwrites it before anything raises.
Closes https://github.com/astral-sh/ty/issues/4958.