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

Adopt ParamSpec for type hints #11711

@squahtx

Description

@squahtx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-TaskRefactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions