@@ -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,34 @@ 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+ # flags: --python-version 3.10
849+ from typing import TypeVar
850+
851+ class U:
852+ a: int
853+ class V:
854+ b: int
855+ class W:
856+ c: int
857+
858+ T = TypeVar("T", bound=U | V | W)
859+
860+ def f(x: T) -> None:
861+ x.a # E
862+ x.b = 1 # E
863+ del x.c # E
864+
865+ [builtins fixtures/tuple.pyi]
866+ [out]
867+ main:14: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a"
868+ main:14: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a"
869+ main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b"
870+ main:15: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b"
871+ main:16: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
872+ main:16: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
873+
874+
847875[case testSubtypingIterableUnpacking1]
848876# https://github.com/python/mypy/issues/11138
849877from typing import Generic, Iterator, TypeVar
0 commit comments