PEP-612 adds ParamSpec
, which will allow us to correctly annotate:
- Decorators which preserve parameters and return types. These will no longer require
cast
s.
- Decorators which change the return type can be correctly annotated and type checked.
- Basically anything that handles
*args
and **kwargs
.
mypy 0.931
(blocked on #11712)
As of mypy 0.931, basic ParamSpec
usage is supported, plus P.args
and P.kwargs
. These styles of function can be annotated:
def decorate(f: Callable[P, R]) -> Callable[P, Optional[R]]:
def wrapped(*args: P.args, **kwargs: P.kwargs) -> Optional[R]:
...
def call(f: Callable[P, R], *args: P.args, **kwargs: P.kwargs) -> R:
...
Concatenate
and def call(f: Callable[P, R], *args: P.args, some_flag: bool = False, **kwargs: P.kwargs)
(extra kwarg) don't work yet.