Skip to content

Commit 9cbd210

Browse files
authored
Add test for new union syntax on generic bounds (#11431)
Closes #10949
1 parent e324460 commit 9cbd210

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

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

+29-1
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,34 @@ 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+
# 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
849877
from typing import Generic, Iterator, TypeVar

0 commit comments

Comments
 (0)