ruff
2abaff04 - [ty] Narrow on negative subscript indexing (#22682)

Commit
7 days ago
[ty] Narrow on negative subscript indexing (#22682) ## Summary Negative subscripts are also indicative of a thing being subcriptable: ```python class Subscriptable: def __getitem__(self, key: int) -> int: return 42 class NotSubscriptable: ... def _(x: list[Subscriptable | NotSubscriptable]): if not isinstance(x[-1], NotSubscriptable): # After narrowing, x[-1] excludes NotSubscriptable, which means subscripting works reveal_type(x[-1]) # revealed: Subscriptable & ~NotSubscriptable reveal_type(x[-1][0]) # revealed: int ```
Author
Parents
Loading