Consider the following code:
class A(object):
a = []
@classmethod
def eat(cls, func):
print "called", func
cls.a.append(func)
class B(A):
@A.eat
def apple(self, x):
print x
A.eat(lambda x: x + 1)
print A.a
Output: called <function apple at 0x1048fba28>
called <function <lambda> at 0x1048fbaa0>
[<function apple at 0x1048fba28>, <function <lambda> at 0x1048fbaa0>]
I expected it to A.abe empty, since we did not even create the object. How is the function added here 2? What exactly calls times eatto call 2?
source
share