Type guard doesn't intersect types like instance check
The type guard doesn't seem to work like an instance check:
from typing import TypeGuard, Any class X: pass class Y: pass x: X = X() assert isinstance(x, Y) def f(z: Any) -> TypeGuard[Y]: return isinstance(z, Y) reveal_type(x) # Revealed type is "a.<subclass of "X" and "Y">", which is great! x2: X assert f(x2) reveal_type(x2) # Revealed type is "a.Y", which is unfortunate.
This is causing problems with the definition of dataclasses.is_dataclass python/typeshed#9723.
The above code was tested with MyPy and Pyright.