Similar to How to distinguish an instance method, a class method, a static method or a function in Python 3?, I would like to determine whether a given method is a class method or a static method.
In that answer it is described how to print the type
in order to determine this. For example,
class Resource(object):
@classmethod
def parse_class(cls, string):
pass
@staticmethod
def parse_static(string):
pass
# I would like to turn these print statements into Booleans
print type(Resource.__dict__['parse_class'])
print type(Resource.__dict__['parse_static'])
prints the output
<type 'classmethod'>
<type 'staticmethod'>
I would like to take this one step further, however, and write a Boolean expression for whether a method is a class or static method.
Any ideas how to go about this? (I've had a look at the types module but none of the types seem like classmethod
or staticmethod
).