Skip to content

Commit

Permalink
Add tests for generic classes and tuple/callable special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
brianschubert committed Nov 21, 2024
1 parent a5e3cb5 commit d1c756b
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,8 @@ A = Union[int, List[A]]
def func(x: A) -> int: ...
[builtins fixtures/tuple.pyi]

[case testAliasExplicitNoArgsNotGeneric]
from typing import List, assert_type
[case testAliasExplicitNoArgsBasic]
from typing import Any, List, assert_type
from typing_extensions import TypeAlias

Implicit = List
Expand All @@ -1249,4 +1249,45 @@ Explicit: TypeAlias = List
x1: Implicit[str]
x2: Explicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
assert_type(x1, List[str])
assert_type(x2, List[Any])
[builtins fixtures/tuple.pyi]

[case testAliasExplicitNoArgsGenericClass]
# flags: --python-version 3.9
from typing import Any, assert_type
from typing_extensions import TypeAlias

Implicit = list
Explicit: TypeAlias = list

x1: Implicit[str]
x2: Explicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
assert_type(x1, list[str])
assert_type(x2, list[Any])
[builtins fixtures/tuple.pyi]

[case testAliasExplicitNoArgsTuple]
from typing import Any, Tuple, assert_type
from typing_extensions import TypeAlias

Implicit = Tuple
Explicit: TypeAlias = Tuple

x1: Implicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
x2: Explicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
assert_type(x1, Tuple[Any, ...])
assert_type(x2, Tuple[Any, ...])
[builtins fixtures/tuple.pyi]

[case testAliasExplicitNoArgsCallable]
from typing import Any, Callable, assert_type
from typing_extensions import TypeAlias

Implicit = Callable
Explicit: TypeAlias = Callable

x1: Implicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
x2: Explicit[str] # E: Bad number of arguments for type alias, expected 0, given 1
assert_type(x1, Callable[..., Any])
assert_type(x2, Callable[..., Any])
[builtins fixtures/tuple.pyi]

0 comments on commit d1c756b

Please sign in to comment.