class A: def foo(self): return 1 def __call__(self): return 10 def cow(self): return -1 def moo(self): return -10 def switch(self): self.foo = self.cow self.__call__ = self.moo class B(object): def foo(self): return 2 def __call__(self): return 20 def cow(self): return -2 def moo(self): return -20 def switch(self): self.foo = self.cow self.__call__ = self.moo self._B__call__ = self.moo setattr(self, '__call__', self.moo) setattr(self, '_B__call__', self.moo) class MyMeta(type): pass class C: __metaclass__ = MyMeta def foo(self): return 3 def __call__(self): return 30 def cow(self): return -3 def moo(self): return -30 def switch(self): self.foo = self.cow self.__call__ = self.moo a = A() b = B() c = C() assert a.foo() == 1, a.foo() assert b.foo() == 2, b.foo() assert c.foo() == 3, c.foo() assert a() == 10, a() assert b() == 20, b() assert c() == 30, c() a.switch() b.switch() c.switch() assert a.foo() == -1, a() assert b.foo() == -2, b() assert c.foo() == -3, c() assert a() == -10, a() assert b() == -20, b() assert c() == -30, c() print 'A-OK!'