Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LambdaType vs FunctionType

What's the difference? docs show nothing on this, and their help() is identical. Is there an object for which isinstance will fail with one but not other?

like image 884
OverLordGoldDragon Avatar asked Jun 19 '20 22:06

OverLordGoldDragon


2 Answers

Back in 1994 I wasn't sure that we would always be using the same implementation type for lambda and def. That's all there is to it. It would be a pain to remove it, so we're just leaving it (it's only one line). If you want to add a note to the docs, feel free to submit a PR.

like image 175
Guido van Rossum Avatar answered Nov 10 '22 09:11

Guido van Rossum


See cpython/Lib/types.py:

def _f(): pass
FunctionType = type(_f)
LambdaType = type(lambda: None)         # Same as FunctionType
like image 5
Mateen Ulhaq Avatar answered Nov 10 '22 09:11

Mateen Ulhaq