Why are class methods not classmethods?
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Tue Nov 27 04:12:28 EST 2007
There's some subtle behaviour going on here that I don't really follow.
Class methods apparently aren't classmethods.
>>> class Parrot(object):
... def method(self, *args):
... return self, args
... @classmethod
... def cmethod(cls, *args):
... return cls, args
...
>>> type(parrot.method) # as expected
<type 'instancemethod'>
>>> type(parrot.cmethod) # I don't expect this result
<type 'instancemethod'>
>>> type(classmethod(parrot.method))
<type 'classmethod'>
>>>
>>> parrot.cm = classmethod(parrot.method)
>>> type(parrot.cm) # I expect this
<type 'classmethod'>
>>>
>>> Parrot.CM = classmethod(parrot.method)
>>> type(Parrot.CM) # but not this
<type 'instancemethod'>
Can anyone explain why class methods bound to a class are instancemethods
rather than classmethods?
--
Steven.
More information about the Python-list
mailing list