是否有任何Python类型提示语法说明一个函数采用与另一个函数相同的参数(和参数类型?特别是在包装时很有用,例如
async def do_stuff(
param1: str,
param2: int,
param3: int,
):
...
def run_async_thing(*args, **kwargs): # <--- What can I put here to say 'takes args like `do_stuff`'?
return asyncio.get_event_loop().run_until_complete(do_stuff(*args, **kwargs))
在这种情况下,我想向run_async_thing
函数添加类型提示以标识它期望与do_stuff
函数具有相同的参数类型。
这是否可能,如果可能,如何?
明确定义参数。您不必要泛化run_asyn_thing
的签名:
def run_async_thing(p1: str, p2: int, p3: int):
return asyncio.get_event_loop().run_until_complete(do_stuff(p1, p2, p3))