Closed
Description
This is probably an easy-ish enhancement. If you check the following code:
from typing import Union, Set
x: Set[int] = {1, 2}
y: Union[int, str] = 1
if y in x:
x.remove(y)
You get an error: Argument 1 to "remove" of "set" has incompatible type "Union[int, str]"; expected "int"
. However, obviously this can never happen; inside the conditional, the type of y must be an int because we know that it's contained within a set of Ints. This issue comes up with all typed container types.
It gets a bit more complex if the container type itself is a container of a Union type, but I think the correct rule here is that "y is contained in x implies the type of y is the intersection of the possible types of y and the types x can contain".