Python 3.4 中抽象类方法 abc.py 的实现如下所示:
class abstractclassmethod(classmethod):
__isabstractmethod__ = True
def __init__(self, callable):
callable.__isabstractmethod__ = True
super().__init__(callable)
Run Code Online (Sandbox Code Playgroud)
Python 2.7 Combine abc.abstractmethod and classmethod的答案就是基于这个实现。
为什么需要在可调用对象上设置 __isabstractmethod__?设置类abstractclassmethod 的类变量__isabstractmethod__ 还不够吗?如果整个 __init__() 定义将被删除(如抽象属性中),哪个用例将不起作用?