I am looking for a way to intercept instance method calls in class MyWrapper
below:
class SomeClass1:
def a1(self):
self.internal_z()
return "a1"
def a2(self):
return "a2"
def internal_z(self):
return "z"
class SomeClass2(SomeClass1):
pass
class MyWrapper(SomeClass2):
# def INTERCEPT_ALL_FUNCTION_CALLS():
# result = Call_Original_Function()
# self.str += result
# return result
def __init__(self):
self.str = ''
def getFinalResult(self):
return self.str
x = MyWrapper()
x.a1()
x.a2()
I want to intercept all function calls make through my wrapper class. In my wrapper class I want to keep track of all the result strings.
result = x.getFinalResult()
print result == 'a1a2'
retvals = []
withself.retvals = []
, 2) in the case of the OPx.getFinalResult()
will return za1a2 not a1a2 , 3) i think it's better to useinspect.ismethod
orcallable(attr)
instead ofhasattr(attr, '__call__')
. – Jarry