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?