I have an abstract Model class, with several abstract methods, what should I put in the body of the methods?
Return
class Model(metaclass=ABCMeta): @abstractmethod def foo(self): return
Pass
class Model(metaclass=ABCMeta): @abstractmethod def foo(self): pass
Descriptive error increase
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.__init__.__name__))
Normally, I would implement method 3 and raise an error, but it looks like it would be redundant, since Python is causing me an error:
>>> 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, what is the best practice? Or is there another way I have to deal with this?
Shayn source share