Skip to content

Commit 7bb0cdc

Browse files
committed
Add test cases from #12134 by @sobolevn
1 parent 7ea5ff6 commit 7bb0cdc

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test-data/unit/check-type-aliases.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,3 +993,28 @@ x_bad: A[bytes] # E: Value of type variable "S" of "A" cannot be "bytes"
993993
B = List[C[U]]
994994
y: B[int]
995995
y_bad: B[str] # E: Type argument "str" of "B" must be a subtype of "int"
996+
997+
[case testTupleWithDifferentArgsPy38]
998+
# flags: --python-version 3.8
999+
NotYet1 = tuple[float] # E: "tuple" is not subscriptable
1000+
NotYet2 = tuple[float, float] # E: "tuple" is not subscriptable
1001+
[builtins fixtures/tuple.pyi]
1002+
1003+
[case testTupleWithDifferentArgsStub]
1004+
# https://github.com/python/mypy/issues/11098
1005+
import tup
1006+
1007+
[file tup.pyi]
1008+
Correct1 = str | tuple[float, float, str]
1009+
Correct2 = tuple[float] | str
1010+
Correct3 = tuple[float, ...] | str
1011+
1012+
RHSAlias1: type = tuple[int, int]
1013+
RHSAlias2: type = tuple[int]
1014+
RHSAlias3: type = tuple[int, ...]
1015+
1016+
# Wrong:
1017+
1018+
WrongTypeElement = str | tuple[float, 1] # E: Invalid type: try using Literal[1] instead?
1019+
WrongEllipsis = str | tuple[float, float, ...] # E: Unexpected "..."
1020+
[builtins fixtures/tuple.pyi]

test-data/unit/pythoneval.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,3 +1816,21 @@ def foo(k: str) -> TD:
18161816
return x.get(k, {})
18171817
[out]
18181818
_testTypedDictUnionGetFull.py:11: note: Revealed type is "TypedDict('_testTypedDictUnionGetFull.TD', {'x'?: builtins.int, 'y'?: builtins.int})"
1819+
1820+
[case testTupleWithDifferentArgsPy310]
1821+
# https://github.com/python/mypy/issues/11098
1822+
# flags: --python-version 3.10
1823+
Correct1 = str | tuple[float, float, str]
1824+
Correct2 = tuple[float] | str
1825+
Correct3 = tuple[float, ...] | str
1826+
1827+
RHSAlias1: type = tuple[int, int]
1828+
RHSAlias2: type = tuple[int]
1829+
RHSAlias3: type = tuple[int, ...]
1830+
1831+
# Wrong:
1832+
WrongTypeElement = str | tuple[float, 1]
1833+
WrongEllipsis = tuple[float, float, ...] | str
1834+
[out]
1835+
_testTupleWithDifferentArgsPy310.py:12: error: Invalid type: try using Literal[1] instead?
1836+
_testTupleWithDifferentArgsPy310.py:13: error: Unexpected "..."

0 commit comments

Comments
 (0)