Strange use of Lambda arrow

Cameron Simpson cs at cskk.id.au
Fri Jun 5 18:23:10 EDT 2020


On 06Jun2020 02:40, Chris Angelico <rosuav at gmail.com> wrote:
>On Sat, Jun 6, 2020 at 2:36 AM Agnese Camellini
><agnese.camellini at gmail.com> wrote:
>>
>> Hello to everyone, lately i building up an open source project, with some
>> collaborator, but one of them cannot contribute any more. He is a solution
>> architect so he is very skilled (much more than me!). I am now analysing
>> his code to finish the job but i don't get this use of the lambda arrow,
>> it's like he is deplaring the returned tipe in the function signature (as
>> you would do in Java). I have never seen something like this in python..
>>
>> Can someone please explain to me this usage (the part regarding the
>> question is highlighted in yellow):
>>
>>     @classmethod
>>     def extract_document_data(cls, file_path : str) -> DocumentData:
>
>I don't know what you highlighted in yellow, as that part didn't come
>through. But in Python, that arrow has nothing to do with lambda
>functions; it is exactly as you describe, annotating a function with
>the type of its return value.

The OP may be being confused by JavaScript, where they have "arrow 
functions", which are what Python calls lambda: anonymous functions. It 
uses an arrow in the syntax:

    (x,y) -> x+y

To reiterate what Chris said: in Python the -> is just a type 
annotation, indicating the expected return type(s) for a function.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-list mailing list