-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Paramspec cannot be used as tuple/dict #12386
Comments
I just closed #12660 as a duplicate. Here's the repro from that issue, by @rbroderi: from typing import TypeVar, Callable, ParamSpec
from functools import wraps
P = ParamSpec("P")
R = TypeVar("R")
def dec_test(func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
def inner(*args: P.args, **kwargs: P.kwargs) -> R:
for a in args: # error: "P.args" has no attribute "__iter__" (not iterable)
print(a)
for arg_k, arg_v in kwargs.items(): # error: "P.kwargs" has no attribute "items"
print(f"{arg_k},{arg_v}")
return func(*args, **kwargs)
return inner Playground link: https://mypy-play.net/?mypy=latest&python=3.10&gist=52d9dbf3999e25e8a72c3bb20c1cb097 |
I don't think that this is fully fixed, a slight variation using destructuring doesn't work: from collections.abc import Callable
from typing import ParamSpec
P = ParamSpec("P")
def foo(func: Callable[P, None]) -> None:
def _inner(*args: P.args, **kwargs: P.kwargs) -> None:
x, *y = args See https://mypy-play.net/?mypy=latest&python=3.10&gist=0c605f87eb31c12b25c7da8f7c2819cd. You get the error: |
@svenpanne, I fixed that just the other day in #13459. It'll be included in the next mypy release (0.980). |
Bug Report
I face issues, when using ParamSpec.args as a tuple and ParamSpec.kwargs as a dict
To Reproduce
Execute mypy on the following code
Expected Behavior
It works
Actual Behavior
Error:
test.py:8:13: error: "P.kwargs" has no attribute "pop" [attr-defined]
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: