Question on difference between LambdaType and FunctionType
On Mon, Nov 26, 2018 at 6:06 AM Iwo Herka <iwoherka at gmail.com> wrote:
> Can someone please provide a use-case for having LambdaType
> separate to FunctionType?
Clarification: This is talking about the 'types' module.
> Since they are equal
> (LambdaType == FunctionType) it seems a bit superfluous to me.
> For example, I cannot do the following:
> if type(foo) is FunctionType and not type(foo) is LambdaType:
I was actually unaware of LambdaType even existing. Obviously it has
to be the same as FunctionType (even more strongly than you put it:
"types.LambdaType is types.FunctionType"), so I agree, it's
superfluous. Maybe it's in case some other Python implementation might
That said, though: if you want to distinguish a lambda function from a
def function, you can do so with reasonable reliability using the
>>> def is_lambda(f): return f.__name__ == "<lambda>"
>>> is_lambda(lambda x: x+1)