from typing import TypeVar
class A:
a: int
class B:
b: int
T = TypeVar("T", bound=A | B)
def foo(t: T):
if isinstance(t, B):
t.b
else:
t.a # error: Item "B" of the upper bound "Union[A, B]" of type variable "T" has no attribute "a"
https://mypy-play.net/?mypy=0.961&python=3.10&gist=024a91f8de4727ab17e124696dc58994
https://mypy-play.net/?mypy=0.961&python=3.10&gist=024a91f8de4727ab17e124696dc58994