On Sat, Nov 28, 2020 at 10:02 AM Abdulla Al Kathiri <
alkathiri.abdu...@gmail.com> wrote:

> Initially, when I wrote this, I had a similar syntax to what you wrote. I
> like it, I changed it to brackets so we could contain Callable that has
> multiple arguments or return value as Callables themselves.
>
> E.g., function that has two Callables as arguments and a Callable return
> looks like this..
>
> f: ((int, str) -> int, (…) -> str) -> (str) -> int
>
> The arguments are clear to me but the callable return confuses me a little
> (the last two ->’s). However,  the return value does’t have parenthesis, I
> still could see the consistency (arguments) -> return. But my mind is
> focusing on the last item, int, instead of the whole (str) -> int for some
> reason.
>

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.

>
> [[int, str -> int], [… -> str] -> [str -> int]] looks uglier but the one
> before last “->" clearly communicates that the return value is callable.
>
>
> 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.
>

Indeed. Shantanu did some quick counting and found that after 'Any' and the
types covered by PEP 585, Callable is by far the most used:
https://bugs.python.org/issue42102#msg381155

-- 
--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-change-the-world/>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/J2NQDICIZZTVRPIPLZ5UXOYRXZXCCAKC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to