from inspect import ismethod
class Call:
def __call__(self):
pass
class Foo:
def __init__(self):
self.var = Call()
def method(self):
pass
foo = Foo()
def method_exists(instance, method):
return hasattr(instance, method) and ismethod(getattr(instance, method))
print(method_exists(foo, "method"))
print(method_exists(foo, "var"))
ZnJvbSBpbnNwZWN0IGltcG9ydCBpc21ldGhvZAoKY2xhc3MgQ2FsbDoKICAgIGRlZiBfX2NhbGxfXyhzZWxmKToKICAgICAgICBwYXNzCgpjbGFzcyBGb286CiAgICBkZWYgX19pbml0X18oc2VsZik6CiAgICAgICAgc2VsZi52YXIgPSBDYWxsKCkKCiAgICBkZWYgbWV0aG9kKHNlbGYpOgogICAgICAgIHBhc3MKCmZvbyA9IEZvbygpCgoKZGVmIG1ldGhvZF9leGlzdHMoaW5zdGFuY2UsIG1ldGhvZCk6CiAgICByZXR1cm4gaGFzYXR0cihpbnN0YW5jZSwgbWV0aG9kKSBhbmQgaXNtZXRob2QoZ2V0YXR0cihpbnN0YW5jZSwgbWV0aG9kKSkKICAgIAoKcHJpbnQobWV0aG9kX2V4aXN0cyhmb28sICJtZXRob2QiKSkKcHJpbnQobWV0aG9kX2V4aXN0cyhmb28sICJ2YXIiKSk=