This is kind of ugly, but it works. Basically, you can use dir
to get a full list of all attributes/methods supported by this class. Then, you can use the class __dict__
to get what's actually defined in that class itself. Below, for any attr that's defined in the base class and not actually defined in the current class, we monkey-patch it to point at our own routine to raise an exception.
class Bidon2(Bidon):
def method_1(self):
print 'New method 1'
def raise_attr_error(self):
raise AttributeError, 'Attribute not supported!'
def __init__(self):
all_funcs = [x for x in dir(self) if not x.startswith('_')]
all_funcs = [x for x in all_funcs if x not in Bidon2.__dict__]
for x in all_funcs:
setattr(self, x, self.raise_attr_error)