First of all, I understand how, in general, a decorator work. And I know @staticmethod
strips off the instance argument in the signature, making
class C(object):
@staticmethod
def foo():
print 'foo'
C.foo //<function foo at 0x10efd4050>
C().foo //<function foo at 0x10efd4050>
valid.
However, I don't understand how the sourcec code of staticmethod
make this happen.
It seems to me that when wrapping method foo
in staticmethod
, an instance of staticmethod
is instantiated, then some magic happens, making C.foo()
legit.
So.. what happen in those magic? what did staticmethod
do?
I'm aware the enormous topics on SO regarding staticmethods
but none of them addresses my doubts. But maybe I didn't hit the magic keyword. If so, please kindly let me know.
For whoever looking for staticmethod
source code, please refer to https://hg.python.org/cpython/file/c6880edaf6f3/Objects/funcobject.c