Skip to content

Commit 1539ea1

Browse files
committed
add testTypeVarBoundToNewUnionAttributeAccess
1 parent 62b4091 commit 1539ea1

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

test-data/unit/check-generic-subtyping.test

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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]
822822
from typing import Union, TypeVar
823823

824824
class U:
@@ -844,6 +844,32 @@ main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T
844844
main: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
849875
from typing import Generic, Iterator, TypeVar

0 commit comments

Comments
 (0)