Skip to content

Commit

Permalink
Add test cases from #12134 by @sobolevn
Browse files Browse the repository at this point in the history
  • Loading branch information
JukkaL committed Nov 25, 2022
1 parent 7ea5ff6 commit 7bb0cdc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -993,3 +993,28 @@ x_bad: A[bytes] # E: Value of type variable "S" of "A" cannot be "bytes"
B = List[C[U]]
y: B[int]
y_bad: B[str] # E: Type argument "str" of "B" must be a subtype of "int"

[case testTupleWithDifferentArgsPy38]
# flags: --python-version 3.8
NotYet1 = tuple[float] # E: "tuple" is not subscriptable
NotYet2 = tuple[float, float] # E: "tuple" is not subscriptable
[builtins fixtures/tuple.pyi]

[case testTupleWithDifferentArgsStub]
# https://github.com/python/mypy/issues/11098
import tup

[file tup.pyi]
Correct1 = str | tuple[float, float, str]
Correct2 = tuple[float] | str
Correct3 = tuple[float, ...] | str

RHSAlias1: type = tuple[int, int]
RHSAlias2: type = tuple[int]
RHSAlias3: type = tuple[int, ...]

# Wrong:

WrongTypeElement = str | tuple[float, 1] # E: Invalid type: try using Literal[1] instead?
WrongEllipsis = str | tuple[float, float, ...] # E: Unexpected "..."
[builtins fixtures/tuple.pyi]
18 changes: 18 additions & 0 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -1816,3 +1816,21 @@ def foo(k: str) -> TD:
return x.get(k, {})
[out]
_testTypedDictUnionGetFull.py:11: note: Revealed type is "TypedDict('_testTypedDictUnionGetFull.TD', {'x'?: builtins.int, 'y'?: builtins.int})"

[case testTupleWithDifferentArgsPy310]
# https://github.com/python/mypy/issues/11098
# flags: --python-version 3.10
Correct1 = str | tuple[float, float, str]
Correct2 = tuple[float] | str
Correct3 = tuple[float, ...] | str

RHSAlias1: type = tuple[int, int]
RHSAlias2: type = tuple[int]
RHSAlias3: type = tuple[int, ...]

# Wrong:
WrongTypeElement = str | tuple[float, 1]
WrongEllipsis = tuple[float, float, ...] | str
[out]
_testTupleWithDifferentArgsPy310.py:12: error: Invalid type: try using Literal[1] instead?
_testTupleWithDifferentArgsPy310.py:13: error: Unexpected "..."

0 comments on commit 7bb0cdc

Please sign in to comment.