Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
Revert change to analyze_callable_args
  • Loading branch information
hamdanal committed Feb 22, 2024
commit 0f13c06eb6b6b026ca0acd9a76b17ef8f77b859d
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