@@ -818,7 +818,7 @@ class Y(Generic[T]):
818818 return U() # E: Incompatible return value type (got "U", expected "T")
819819
820820
821- [case testTypeVarBoundToUnionAttributeAccess ]
821+ [case testTypeVarBoundToOldUnionAttributeAccess ]
822822from typing import Union, TypeVar
823823
824824class U:
@@ -844,6 +844,32 @@ main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T
844844main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
845845
846846
847+ [case testTypeVarBoundToNewUnionAttributeAccess]
848+ from typing import TypeVar
849+
850+ class U:
851+ a: float
852+ class V:
853+ b: float
854+ class W:
855+ c: float
856+
857+ T = TypeVar("T", bound=U | V | W)
858+
859+ def f(x: T) -> None:
860+ x.a # E
861+ x.b = 1.0 # E
862+ del x.c # E
863+
864+ [out]
865+ main:13: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a"
866+ main:13: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a"
867+ main:14: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b"
868+ main:14: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b"
869+ main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
870+ main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
871+
872+
847873[case testSubtypingIterableUnpacking1]
848874# https://github.com/python/mypy/issues/11138
849875from typing import Generic, Iterator, TypeVar
0 commit comments