我大量使用python 3提供的python类型支持.
最近,我试图将一个函数作为参数传递,但我找不到使用kwargs
intyping.Callable
签名的任何帮助.
请判断下面的代码和注释.
import typing
# some function with singnature typing
def fn1_as_arg_with_kwargs(a: int, b: float) -> float:
return a + b
# some function with singnature typing
def fn2_as_arg_with_kwargs(a: int, b: float) -> float:
return a * b
# function that get callables as arg
# this works with typing
def function_executor(
a: int,
b: float,
fn: typing.Callable[[int, float], float]):
return fn(a, b)
# But what if I want to name my kwargs
# (something like below which does not work)
# ... this will help me more complex scenarios
# ... or am I expecting a lot from python3 ;)
def function_executor(
a: int,
b: float,
fn: typing.Callable[["a": int, "b": float], float]):
return fn(a=a, b=b)