Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeAliasType #16926

Merged
merged 18 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
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
Next Next commit
.
  • Loading branch information
hamdanal committed Feb 21, 2024
commit c020b79c08c26fec6b9e7344ee7b0c2b9a92b31e
3 changes: 2 additions & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,8 @@ def analyze_callable_args(
if self.defining_alias and self.has_type_params:
tvar_likes = self.find_type_var_likes(arg)
for name, tvar_expr in tvar_likes:
if (name, tvar_expr) not in self.allowed_alias_tvars:
tvar_def = self.tvar_scope.get_binding(name)
if tvar_def is None or tvar_def not in self.allowed_alias_tvars:
self.fail(
f'Type variable "{name}" is not included in type_params',
arglist,
Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -1115,9 +1115,13 @@ reveal_type(xi) # N: Revealed type is "builtins.dict[builtins.int, builtins.str

VariadicAlias1 = TypeAliasType("VariadicAlias1", Tuple[Unpack[Ts]], type_params=(Ts,))
VariadicAlias2 = TypeAliasType("VariadicAlias2", Tuple[Unpack[Ts], K], type_params=(Ts, K))
VariadicAlias3 = TypeAliasType("VariadicAlias3", Callable[[Unpack[Ts]], int], type_params=(Ts,))
xv: VariadicAlias1[int, str] = (1, 'a')
yv: VariadicAlias1[str, int] = (1, 'a') # E: Incompatible types in assignment (expression has type "Tuple[int, str]", variable has type "Tuple[str, int]")
zv: VariadicAlias2[int, str] = (1, 'a')
def int_in_int_out(x: int) -> int: return x
wv: VariadicAlias3[int] = int_in_int_out
reveal_type(wv) # N: Revealed type is "def (builtins.int) -> builtins.int"

ParamAlias = TypeAliasType("ParamAlias", Callable[P, int], type_params=(P,))
def f(x: str, y: float) -> int: return 1
Expand Down
Loading