Additional type annotation for Callable

PEP 604 introduced a new notation for specifying Unions, with X | Y being an alias for typing.Union[X, Y]. While thinking about other notations that could be useful, I would like to suggest also having

[ArgType1, ArgType2, ArgType3] -> ReturnType

as an alternative for

typing.Callable[[ArgType1, ArgType2, ArgType3], ReturnType]

This would then mean that, for example, we could annotate the map function as:

def map(func: [X] -> Y, items: Iterable[X]) -> Iterable[Y]:

Which would make this very similar to the annotation used to define a function that can be passed into map:

def f(x: X) -> Y:

What do people think of this proposal?

FYI most typing discussions takes place on the typing-sig mailing list, although this may have come up on the python-ideas mailing list (I can’t quite remember where I have seen something similar proposed before).


I’m all for shortcuts because the new PEG gramma enables them with a few changes that don’t impact the rest of the compiling process. It also makes Python more like other programming languages with type specifications.

Instead of Callable[...]:

def f(A -> C, List[A]) -> C

Instead of Optional[T]:

def f(A, T?) -> C