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

Adopt ParamSpec for type hints #11711

Open
matrixbot opened this issue Dec 19, 2023 · 0 comments
Open

Adopt ParamSpec for type hints #11711

matrixbot opened this issue Dec 19, 2023 · 0 comments
Labels

Comments

@matrixbot
Copy link
Collaborator

matrixbot commented Dec 19, 2023

This issue has been migrated from #11711.


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.

@matrixbot matrixbot changed the title Dummy issue Adopt ParamSpec for type hints Dec 21, 2023
@matrixbot matrixbot reopened this Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant