typing.Callable takes two "arguments": the argument type(s) and the return type. The argument type should be either ..., for arbitrary arguments, or a list of explicit types (e.g., [str, str, int]).
Is there a way of representing Callables that have exactly the same, albeit arbitrary, signatures for generics?
For example, say I wanted a function that took functions and returned a function with the same signature, I could do this if I knew the function signature upfront:
def fn_combinator(*fn:Callable[[Some, Argument, Types], ReturnType]) -> Callable[[Some, Argument, Types], ReturnType]:
...
However, I don't know the argument types upfront and I want my combinator to be suitably general. I had hoped that this would work:
ArgT = TypeVar("ArgT")
RetT = TypeVar("RetT")
FunT = Callable[ArgT, RetT]
def fn_combinator(*fn:FunT) -> FunT:
...
However, the parser (at least in Python 3.7) doesn't like ArgT in the first position. Is Callable[..., RetT] the best I can do?