Consider a function that wraps another function and outputs the output to a singleton list:
def listify(func):
return lambda *kargs, **kwargs: [func(*kargs, **kwargs)]
How would you type - call this function in python3? This is my best attempt:
from typing import Callable, TypeVar
T = TypeVar('T')
def listify(func: Callable[..., T]) -> Callable[..., List[T]]:
return lambda *kargs, **kwargs: [func(*kargs, **kwargs)]
But I'm not glad that the returned one Callabledoes not inherit the signature of the input argument types Callable. Is there a way to do this without making assumptions about the number of arguments func?
dshin source
share