Description
I don't know whether this is feasible, but it would be very convenient if variables used in the same iterable-unpacking assignment were "linked" in some way which would make it possible for narrowing the type of one to narrow the type of the other(s).
For example, if a function is typed as returning tuple[int, int] | tuple[None, None] and its return value is unpacked, narrowing one of the unpacked values to not None would ideally narrow the other, as well.
from random import random
from typing import reveal_type
def get_tuple() -> tuple[int, int] | tuple[None, None]:
if random() < 0.5:
return 1, 2
return None, None
first, second = get_tuple()
if first is not None:
reveal_type(first) # Reveals "int".
reveal_type(second) # Reveals "int | None", but "int" would be better.
(playground link)
Both Pyright and Mypy currently behave in the same manner as Basedpyright, so I assume this isn't trivial. 😅
Description
I don't know whether this is feasible, but it would be very convenient if variables used in the same iterable-unpacking assignment were "linked" in some way which would make it possible for narrowing the type of one to narrow the type of the other(s).
For example, if a function is typed as returning
tuple[int, int] | tuple[None, None]and its return value is unpacked, narrowing one of the unpacked values tonot Nonewould ideally narrow the other, as well.(playground link)
Both Pyright and Mypy currently behave in the same manner as Basedpyright, so I assume this isn't trivial. 😅