#!/usr/bin/python
class Bar(object):
@staticmethod
def ruleOn(rule):
if isinstance(rule, tuple):
print rule[0]
print rule[0].__get__(None, Foo)
else:
print rule
class Foo(object):
@classmethod
def callRule(cls):
Bar.ruleOn(cls.RULE1)
Bar.ruleOn(cls.RULE2)
@classmethod
def check(cls):
print "I am check"
RULE1 = check
RULE2 = (check,)
Foo.callRule()
Output:
<bound method type.check of <class '__main__.Foo'>>
<classmethod object at 0xb7d313a4>
<bound method type.check of <class '__main__.Foo'>>
As you can see I'm trying to store a reference to a classmethod function in a tuple for future use.
However, it seems to store the object itself rather then reference to the bound function.
As you see it works for a variable reference.
The only way to get it is to use __get__
, which requires the name of the class it belongs to, which is not available at the time of the RULE
variable assignment.
Any ideas anyone?