How can I test whether a variable holds a lambda?

前端 未结 5 1511
灰色年华
灰色年华 2021-02-04 00:19

Is there a way to test whether a variable holds a lambda? The context is I\'d like to check a type in a unit test:

self.assertEquals(lambda, type(my         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 01:09

    def isalambda(v):
      LAMBDA = lambda:0
      return isinstance(v, type(LAMBDA)) and v.__name__ == LAMBDA.__name__
    

提交回复
热议问题