@@ -818,7 +818,7 @@ class Y(Generic[T]):
818
818
return U() # E: Incompatible return value type (got "U", expected "T")
819
819
820
820
821
- [case testTypeVarBoundToUnionAttributeAccess ]
821
+ [case testTypeVarBoundToOldUnionAttributeAccess ]
822
822
from typing import Union, TypeVar
823
823
824
824
class U:
@@ -844,6 +844,34 @@ main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T
844
844
main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
845
845
846
846
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
+
847
875
[case testSubtypingIterableUnpacking1]
848
876
# https://github.com/python/mypy/issues/11138
849
877
from typing import Generic, Iterator, TypeVar
0 commit comments