Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests for generic classes and tuple/callable special cases
  • Loading branch information
brianschubert committed Nov 21, 2024
commit d1c756bc5a8b93359f2b094e9edfeee293b65029
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]