Skip to content

Commit

Permalink
Revert change to analyze_callable_args
Browse files Browse the repository at this point in the history
  • Loading branch information
hamdanal committed Feb 22, 2024
1 parent 994fbb9 commit 0f13c06
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
11 changes: 0 additions & 11 deletions mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,17 +1452,6 @@ def analyze_callable_args(
and self.refers_to_full_names(arg, ("typing_extensions.Unpack", "typing.Unpack"))
or isinstance(arg, UnpackType)
):
if self.defining_alias and self.has_type_params:
tvar_likes = self.find_type_var_likes(arg)
for name, tvar_expr in tvar_likes:
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,
code=codes.VALID_TYPE,
)
return None
if seen_unpack:
# Multiple unpacks, preserve them, so we can give an error later.
if i == len(arglist.items) - 1 and not invalid_unpacks:
Expand Down
7 changes: 4 additions & 3 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ BadAlias1 = TypeAliasType("BadAlias1", tuple[*Ts]) # E: TypeVarTuple "Ts" is no
ba1: BadAlias1[int] # E: Bad number of arguments for type alias, expected 0, given 1
reveal_type(ba1) # N: Revealed type is "builtins.tuple[Any, ...]"

BadAlias2 = TypeAliasType("BadAlias2", Callable[[*Ts], str]) # E: Type variable "Ts" is not included in type_params
ba2: BadAlias2[int] # E: Bad number of arguments for type alias, expected 0, given 1
reveal_type(ba2) # N: Revealed type is "Any"
# TODO this should report errors on the two following lines
#BadAlias2 = TypeAliasType("BadAlias2", Callable[[*Ts], str])
#ba2: BadAlias2[int]
#reveal_type(ba2)

[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]
7 changes: 4 additions & 3 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -1185,9 +1185,10 @@ Ta9 = TypeAliasType("Ta9", Callable[P, T]) # E: ParamSpec "P" is not included i
unbound_ps_alias3: Ta9[int, str] # E: Bad number of arguments for type alias, expected 0, given 2
reveal_type(unbound_ps_alias3) # N: Revealed type is "def [P] (*Any, **Any) -> Any"

Ta10 = TypeAliasType("Ta10", Callable[[Unpack[Ts]], str]) # E: Type variable "Ts" is not included in type_params
unbound_tvt_alias2: Ta10[int] # E: Bad number of arguments for type alias, expected 0, given 1
reveal_type(unbound_tvt_alias2) # N: Revealed type is "Any"
# TODO this should report errors on the two following lines
#Ta10 = TypeAliasType("Ta10", Callable[[Unpack[Ts]], str])
#unbound_tvt_alias2: Ta10[int]
#reveal_type(unbound_tvt_alias2)

[builtins fixtures/dict.pyi]

Expand Down

0 comments on commit 0f13c06

Please sign in to comment.