Take the following minimal example:
import abc
class FooClass(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def FooMethod(self):
raise
Well, if you must do it this way, then you could just pass a dummy dict {'FooMethod':None}
as the third argument to type. This allows derived_type
to satisfy ABCMeta's requirement that all abstract methods be overridden. Later on you can supply the real FooMethod
:
def main():
derived_type = type('Derived', (FooClass,), {'FooMethod':None})
def BarOverride(self):
print 'Hello, world!'
setattr(derived_type, 'FooMethod', BarOverride)
instance = derived_type()