Files
Charlie Marsh 3cd7c51898 [ty] Record exception checkpoints for nested unpacking targets (#30206)
## 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.
2026-11-10 11:38:31 +01:00
..