You can override type creation with Python metaclasses. Here after object creation, I replace parent's __call__
method with another one throwing an exception:
>>> class A(object):
def __call__(self):
print 'Called !'
>>> class MetaNotCallable(type):
@staticmethod
def call_ex(*args, **kwargs):
raise NotImplementedError()
def __new__(mcs, name, bases, dict):
obj = super(MetaNotCallable, mcs).__new__(mcs, name, bases, dict)
obj.__call__ = MetaNotCallable.call_ex # Change method !
return obj
>>> class B(A):
__metaclass__ = MetaNotCallable
>>> a = A()
>>> a()
Called !
>>> b = B()
>>> b()
Traceback (most recent call last):
File "<pyshell#131>", line 1, in <module>
b()
File "<pyshell#125>", line 4, in call_ex
raise NotImplementedError()
NotImplementedError