Skip to content

Commit 9ca1deb

Browse files
committed
add testTypeVarBoundToNewUnionAttributeAccess
1 parent 62b4091 commit 9ca1deb

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

mypy/test/testcheck.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
typecheck_files.append('check-python38.test')
105105
if sys.version_info >= (3, 9):
106106
typecheck_files.append('check-python39.test')
107+
if sys.version_info >= (3, 10):
108+
typecheck_files.append('check-python310.test')
107109

108110
# Special tests for platforms with case-insensitive filesystems.
109111
if sys.platform in ('darwin', 'win32'):

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

Lines changed: 1 addition & 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:

test-data/unit/check-python310.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[case testTypeVarBoundToNewUnionAttributeAccess]
2+
from typing import TypeVar
3+
4+
class U:
5+
a: float
6+
class V:
7+
b: float
8+
class W:
9+
c: float
10+
11+
T = TypeVar("T", bound=U | V | W)
12+
13+
def f(x: T) -> None:
14+
x.a # E
15+
x.b = 1.0 # E
16+
del x.c # E
17+
18+
[out]
19+
main:13: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a"
20+
main:13: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "a"
21+
main:14: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b"
22+
main:14: error: Item "W" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "b"
23+
main:15: error: Item "U" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"
24+
main:15: error: Item "V" of the upper bound "Union[U, V, W]" of type variable "T" has no attribute "c"

0 commit comments

Comments
 (0)