Expose function args from high order function #7910
Answered
by
erictraut
Tomperez98
asked this question in
Q&A
-
from __future__ import annotations
from typing import Callable
from typing_extensions import ParamSpec, TypeVar
P = ParamSpec("P")
T = TypeVar("T")
def run(fn: Callable[P, T]) -> T:
return fn()
def greet(name: str) -> str: ...
def main():
run(greet, name="tomas") # Is there a way to get type annotations for the name argument? Is it possible to have typing annotation for the |
Beta Was this translation helpful? Give feedback.
Answered by
erictraut
May 13, 2024
Replies: 1 comment 2 replies
-
I don't know what you mean by "get the type annotations for the name argument". If you want def run(fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
return fn(*args, **kwargs) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Tomperez98
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know what you mean by "get the type annotations for the name argument".
If you want
run
to accept arguments that it can pass tofn
, you need to include*args
and**kwargs
parameters like this: