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

Allow ParamSpecArgs to be unpacked #13459

Merged
merged 3 commits into from
Aug 20, 2022
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
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
17 changes: 17 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,20 @@ 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.kwargs, **kwargs: P.kwargs) -> str:
hauntsaninja marked this conversation as resolved.
Show resolved Hide resolved
a, *b = args
AlexWaygood marked this conversation as resolved.
Show resolved Hide resolved
reveal_type(a) # N: Revealed type is "builtins.object"
reveal_type(b) # N: Revealed type is "builtins.list[builtins.object]"
d = {**kwargs}
reveal_type(d) # N: Revealed type is "builtins.dict[builtins.str, builtins.object]"
return "foo"
return inner
[builtins fixtures/paramspec.pyi]