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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/checker.py
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
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
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]"
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]