@@ -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,32 @@ 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
+ 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
+
847
873
[case testSubtypingIterableUnpacking1]
848
874
# https://github.com/python/mypy/issues/11138
849
875
from typing import Generic, Iterator, TypeVar
0 commit comments