I am testing the simpleTAL templating library which makes use of callable to test if an object passed into the template is a function or not. The definition of callable says that an object is callable if it contains the magic method __call__
. See also What is a "callable" in Python?.
However, an object created with the following class definition (python 2.7.4)
class H:
def __init__(self, val):
self.a = val
def __getattr__(self, name):
return 'blah'
h = H(1)
callable(h)
will return True. If, however, __getattr__
raises AttributeError, which does not make sense to do systematically, it will return False!
Can someone shed some light on this issue and possibly a solution? (I don't want h to be callable).