-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b05bdad
commit 3260bb0
Showing
6 changed files
with
227 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# static analysis: ignore | ||
from .test_name_check_visitor import TestNameCheckVisitorBase | ||
from .test_node_visitor import assert_passes, skip_before | ||
|
||
|
||
class TestRecursion(TestNameCheckVisitorBase): | ||
@assert_passes() | ||
def test(self): | ||
from typing import Dict, List, Union | ||
|
||
JSON = Union[Dict[str, "JSON"], List["JSON"], int, str, float, bool, None] | ||
|
||
def f(x: JSON): | ||
pass | ||
|
||
def capybara(): | ||
f([]) | ||
f([1, 2, 3]) | ||
f([[{1}]]) # TODO this should throw an error | ||
|
||
|
||
class TestTypeAliasType(TestNameCheckVisitorBase): | ||
@assert_passes() | ||
def test_typing_extensions(self): | ||
from typing_extensions import TypeAliasType, assert_type | ||
|
||
MyType = TypeAliasType("MyType", int) | ||
|
||
def f(x: MyType): | ||
assert_type(x, MyType) | ||
assert_type(x + 1, int) | ||
|
||
def capybara(i: int, s: str): | ||
f(i) | ||
f(s) # E: incompatible_argument | ||
|
||
@assert_passes() | ||
def test_typing_extensions_generic(self): | ||
from typing_extensions import TypeAliasType, assert_type | ||
from typing import TypeVar, Union, List, Set | ||
|
||
T = TypeVar("T") | ||
MyType = TypeAliasType("MyType", Union[List[T], Set[T]], type_params=(T,)) | ||
|
||
def f(x: MyType[int]): | ||
assert_type(x, MyType[int]) | ||
assert_type(list(x), List[int]) | ||
|
||
def capybara(i: int, s: str): | ||
f([i]) | ||
f([s]) # E: incompatible_argument | ||
|
||
@skip_before((3, 12)) | ||
def test_312(self): | ||
self.assert_passes(""" | ||
from typing_extensions import assert_type | ||
type MyType = int | ||
def f(x: MyType): | ||
assert_type(x, MyType) | ||
assert_type(x + 1, int) | ||
def capybara(i: int, s: str): | ||
f(i) | ||
f(s) # E: incompatible_argument | ||
""") | ||
|
||
@skip_before((3, 12)) | ||
def test_312_generic(self): | ||
self.assert_passes(""" | ||
from typing_extensions import assert_type | ||
type MyType[T] = list[T] | set[T] | ||
def f(x: MyType[int]): | ||
assert_type(x, MyType[int]) | ||
assert_type(list(x), list[int]) | ||
def capybara(i: int, s: str): | ||
f([i]) | ||
f([s]) # E: incompatible_argument | ||
""") | ||
|
||
@skip_before((3, 12)) | ||
def test_312_local_alias(self): | ||
self.assert_passes(""" | ||
from typing_extensions import assert_type | ||
def capybara(): | ||
type MyType = int | ||
def f(x: MyType): | ||
assert_type(x, MyType) | ||
assert_type(x + 1, int) | ||
f(1) | ||
f("x") # E: incompatible_argument | ||
""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters