I have an abstract class, Model
, with a few abstract methods, what should I put in the body of the methods?
A return
class Model(metaclass=ABCMeta): @abstractmethod def foo(self): return
A pass
class Model(metaclass=ABCMeta): @abstractmethod def foo(self): pass
Raising a descriptive error
class Model(metaclass=ABCMeta): @abstractmethod def foo(self): raise NotImplementedError("Class {class_name} doesn't implement {func_name} function" .format(class_name=self.__class__.__name__, func_name=self.foo.__name__))
Typically I would implement method 3 and raise an error, however it looks like it would be redundant, as Python raises an error for me:
>>> bar = module.Model()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class Model with abstract methods foo
Between the options presented, which is best practice? Or is there another way I should handle this?