import abc
class A(abc.ABC):
@classmethod
@abc.abstractmethod
def foo(cls):
pass
我无法实例化它(正如预期的那样):
>>> A()
TypeError: Can't instantiate abstract class A with abstract methods foo
但是我可以调用它的抽象方法而没有错误。
>> A.foo()
这种行为有没有文档说明?
已在Python 3.6和3.7上测试。