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.

You can do that with a custom protocol https://docs.python.org/3/library/typing.html#typing.Protocol

@Valentin Berlier That would probably be possible, but the question here is, given that `Callable` is a built-in, is it sensible to expect `Callable` to support this behaviour. I would say yes, because it is extremely intuitive, especially with regards to the fact that the widely used numpy library already uses Ellipsis in a fashion semantically consistent with this proposal.

This is a question for typing-sig. Over on typing-sig we are looking at alternatives to Callable, so it's unlikely that any changes to Callable itself will be accepted. Instead of `...`, we will probably use `*args`, similar to what is used in the `def` syntax. Feel free to peruse the typing-sig archives to learn more about the current status: https://mail.python.org/archives/list/typing-sig@python.org/ --Guido On Wed, Sep 22, 2021 at 1:04 AM Randolf Scholz <randolf.scholz@gmail.com> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

You can do that with a custom protocol https://docs.python.org/3/library/typing.html#typing.Protocol

@Valentin Berlier That would probably be possible, but the question here is, given that `Callable` is a built-in, is it sensible to expect `Callable` to support this behaviour. I would say yes, because it is extremely intuitive, especially with regards to the fact that the widely used numpy library already uses Ellipsis in a fashion semantically consistent with this proposal.

This is a question for typing-sig. Over on typing-sig we are looking at alternatives to Callable, so it's unlikely that any changes to Callable itself will be accepted. Instead of `...`, we will probably use `*args`, similar to what is used in the `def` syntax. Feel free to peruse the typing-sig archives to learn more about the current status: https://mail.python.org/archives/list/typing-sig@python.org/ --Guido On Wed, Sep 22, 2021 at 1:04 AM Randolf Scholz <randolf.scholz@gmail.com> wrote:
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>
participants (3)
-
Guido van Rossum
-
Randolf Scholz
-
Valentin Berlier