0

Just went across internals of ABC collections.

Can anyone please explain what does this construct stand for:

def _f(): pass
FunctionType = type(_f)
del _f

I know I'm probably missing some basic concept(s), please advise where to start/look to understand this?

vtm11
  • 165
  • 1
  • 9
  • 2
    `FunctionType` is supposed to represent the type that functions are. The easiest way for python to record what type a function is, is to create one, _check_ what type it is, and then delete it so that it's not polluting the namespace. – Green Cloak Guy Dec 31 '21 at 13:55
  • 1
    @GreenCloakGuy Any idea why it doesn't do `FunctionType = type(lambda: None)` instead? – Kelly Bundy Jan 03 '22 at 14:57
  • 1
    Presumably because, at some point in the feature, lambdas may become a meaningfully different type than functions, and in that case they'd want to put that in a separate type variable `LambdaType` instead. – Green Cloak Guy Jan 03 '22 at 15:07

0 Answers0