根据文档,它应该可以结合起来@property
,@abc.abstractmethod
因此以下内容应该在 python3.3 中工作:
import abc
class FooBase(metaclass=abc.ABCMeta):
@property
@abc.abstractmethod
def greet(self):
""" must be implemented in order to instantiate """
pass
@property
def greet_comparison(self):
""" must be implemented in order to instantiate """
return 'hello'
class Foo(FooBase):
def greet(self):
return 'hello'
测试实现:
In [6]: foo = Foo()
In [7]: foo.greet
Out[7]: <bound method Foo.greet of <__main__.Foo object at 0x7f935a971f10>>
In [8]: foo.greet()
Out[8]: 'hello'
所以它显然不是一个属性,因为它应该像这样工作:
In [9]: foo.greet_comparison
Out[9]: 'hello'
也许我太笨了,或者它根本不起作用,有人有想法吗?