Created
December 11, 2024 15:53
-
-
Save mypy-play/950f9a8265f17e47fa35de5785208bab to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Protocol, ParamSpec, Callable, Concatenate | |
P = ParamSpec('P') | |
class FuncType(Protocol[P]): | |
def __call__(self, *args: P.args, x: str, **kwargs: P.kwargs) -> str: ... | |
def wrapper(fp: Callable[P, str]) -> FuncType[P]: | |
def inner(*args: P.args, x: str, **kwargs: P.kwargs) -> str: | |
print(x) | |
return fp(*args, **kwargs) | |
return inner | |
def my_f(s: str, d: float) -> str: | |
return f"{s}, {d}" | |
wrapped = wrapper(my_f) | |
wrapped(1.2, x="works?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment