I will be very happy if those versions of Callable and anonymous functions
exist in Python right now. See how elegant that would look like..
def func(x: int, y: int, f: (int, int) -> int) -> int:
return f(x, y)
print(func(3, 4, (x, y) => x + y)) #Out: 7
Imagine your mouse is on :func: ‘func’ in VSC or PyCharm and see that you need
the third parameter to be of type (int, int) -> int, you can immediately write
an anonymous function that mirrors the structure of the annotation but instead
of ->, you have =>. Straight forward.
> On 18 Feb 2021, at 12:43 PM, Paul Sokolovsky <[email protected]> wrote:
>
> (x, y) -> x + y translates to: Callable[[x, y], x + y]
>
> while
>
> (x, y) => x + y translates to: lambda x, y: x + y
>
> Huge difference.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/V7KSM464X2ECGWUQFZ5OH4A74LIHF4HG/
Code of Conduct: http://python.org/psf/codeofconduct/