Since you displayed the function as an unrelated method A , so when you call cls.func , you first set something equal to getattr(cls, 'func') , which returns the <unbound method A.task> BUT, you need to call this unbound method with the class as the first argument.
Since cls.func in this particular case means βgives me the class attribute func of cls β, it cannot mean β func class methodβ at the same time - it means Python does not translate cls.func() to func(cls) .
But at the same time, since func is the <unbound method A.task> (bound to A.task ), it needs to be called as func(cls) to work.
Mark this as follows:
@classmethod def test(cls): print getattr(cls, 'func')
You can fix this with something like:
def task(cls=None): if cls is None: print 'task()' else: print 'A.foo({})'.format(cls) a = task class A: func = task
Output:
task() task() A.foo(<__main__.A instance at 0x7fd0310a46c8>)
Note that python3 removes unrelated methods, this only works with python2.x
source share