Body of abstract method in Python 3.5 [duplicate]

断了今生、忘了曾经 提交于 2019-12-03 06:11:27

The best thing to put in the body of an abstractmethod (or abstractproperty) would be a docstring.

Then you don't need pass or return or ... because a return None is implicitly included - and a docstring makes this construct "compile" without a SyntaxError:

from abc import abstractmethod, ABCMeta

class Model(metaclass=ABCMeta):
    @abstractmethod
    def foo(self):
        """This method should implement how to foo the model."""

The docstring should then explain what should be implemented here so that subclassers know what is/was intended.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!