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