Typing Callable Ellipsis -- support for type hints a la Callable[[int, float, ...], None]
Dear Python community, type hinting is awesome! But recently I stumbled upon the following: I was writing a dictionary of functions that all share a common signature, in that the first two arguments were the same type. However, the functions could differ in the remaining arguments (positional / keyword) When trying to type hint as `Callable[[int, float, ...], None] `, which felt very natural at the time, mypy complained: `error: Unexpected "..."`. I propose to support type hints a la - Callable[[type1, type2, ..., typeN, ...], ReturnType] - Callable[[..., type1, type2, ..., typeN], ReturnType] which should match any callable with matching type hints for the first/last N inputs. (with some special treatment for functions with *args or **kwargs of course). Best regard, Randolf.
participants (3)
-
Guido van Rossum
-
Randolf Scholz
-
Valentin Berlier