Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Adopt ParamSpec for type hints #11711

Open
squahtx opened this issue Jan 10, 2022 · 2 comments
Open

Adopt ParamSpec for type hints #11711

squahtx opened this issue Jan 10, 2022 · 2 comments
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.

Comments

@squahtx
Copy link
Contributor

squahtx commented Jan 10, 2022

PEP-612 adds ParamSpec, which will allow us to correctly annotate:

  • Decorators which preserve parameters and return types. These will no longer require casts.
  • 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.

@squahtx squahtx added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label Jan 10, 2022
@squahtx squahtx mentioned this issue Jan 10, 2022
2 tasks
@squahtx squahtx mentioned this issue Apr 28, 2022
2 tasks
@squahtx
Copy link
Contributor Author

squahtx commented Apr 28, 2022

mypy 0.950 has been released, and includes support for Concatenate. See #12585.

@DMRobertson
Copy link
Contributor

Probably the best way to action this is to grep the source tree for Callable\[\.\.\. or Callable[^\[]]. i.e. looking for Callable[..., <stuff>] and Callable without any square brackets.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

No branches or pull requests

2 participants