Skip to content

Commit

Permalink
Allow ParamSpecArgs to be unpacked (#13459)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Aug 20, 2022
1 parent 5f488e2 commit 7606270
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
TypeTranslator,
TypeType,
TypeVarId,
TypeVarLikeType,
TypeVarType,
UnboundType,
UninhabitedType,
Expand Down Expand Up @@ -3161,7 +3162,7 @@ def check_multi_assignment(
# TODO: maybe elsewhere; redundant.
rvalue_type = get_proper_type(rv_type or self.expr_checker.accept(rvalue))

if isinstance(rvalue_type, TypeVarType):
if isinstance(rvalue_type, TypeVarLikeType):
rvalue_type = get_proper_type(rvalue_type.upper_bound)

if isinstance(rvalue_type, UnionType):
Expand Down
20 changes: 20 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1092,3 +1092,23 @@ def func(callback: Callable[P, str]) -> Callable[P, str]:
return 'baz'
return inner
[builtins fixtures/paramspec.pyi]

[case testUnpackingParamsSpecArgsAndKwargs]
from typing import Callable
from typing_extensions import ParamSpec

P = ParamSpec("P")

def func(callback: Callable[P, str]) -> Callable[P, str]:
def inner(*args: P.args, **kwargs: P.kwargs) -> str:
a, *b = args
reveal_type(a) # N: Revealed type is "builtins.object"
reveal_type(b) # N: Revealed type is "builtins.list[builtins.object]"
c, *d = kwargs
reveal_type(c) # N: Revealed type is "builtins.str"
reveal_type(d) # N: Revealed type is "builtins.list[builtins.str]"
e = {**kwargs}
reveal_type(e) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]"
return "foo"
return inner
[builtins fixtures/paramspec.pyi]

0 comments on commit 7606270

Please sign in to comment.