x = 0

def wrap_class(base, towrap):


    class ClassWrapper(base):

        def __getattribute__(self, name):
            original = base.__getattribute__(self, name)
if name in towrap:

    def func_wrapper(*args, **kwargs):
        global x
x = 1
try:
    return original(*args, **kwargs)
finally:
    x = 0
return func_wrapper
return original
return ClassWrapper


class Base(object):

    def a(self):
        print('a x: %s' % x)

def b(self):
    print('b x: %s' % x)
Wrapped = wrap_class(Base, ('a',))
m = Wrapped()
m.a()
m.b()
m = wrap_class(Base, ('a',))()
Оберните вызовы методов класса Python