On 11/28/20 9:31 AM, Guido van Rossum wrote:
I'm not so keen on the square brackets you propose. How about we write Callable[[x, y], z] as (x, y) -> z instead?
I also like the "(x, y) -> z" syntax a bit better than "[x, y -> z]". (+0.5)
On 11/28/20 3:46 PM, Guido van Rossum wrote:
You could parenthesize the return value if you think it's not clear. (IIRC some functional languages like Haskell use the ... -> ... -> ... notation to indicate functions of multiple arguments, so it's probably good to avoid looking like that -- even if it'sconsistent it would mislead people into thinking that Python uses a similar idiom.
To avoid the "... -> ... -> ... " ambiguity, I'd suggest that kind of chaining be recognized and treated as a syntax error. If describing a Callable that itself returned another Callable, it would then be necessary to parenthesize the return value:
A function that has two Callables as arguments and a Callable return type would then look like: f: ((int, str) -> int, (…) -> str) -> ((str) -> int)
(It's worth noting that I don't think either the original "Callable[[x, y], z]" syntax OR the proposed "(x, y) -> z" syntax is particularly readable when lots of nesting is involved, but I suspect that's just because the type is just complicated. :) )
On 11/28/20 10:02 AM, Abdulla Al Kathiri wrote:
Regardless of how it’s done, the less we depend on the typing module for annotations, the better I think because it encourages python users to annotate their functions.
-- David Foster | Seattle, WA, USA