按照docs它应该工作结合@property
和@abc.abstractmethod
所以下面应该python3.3工作:abc.abstractmethod +物业
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'
也许我是愚蠢的,或者根本行不通,有人有想法?
只是打我:) –
如果你有一个抽象的二传手,会装饰迎接满足覆盖要求?只是一个兴趣点。 –
@ m.brindley:如果'问候在dir(Foo)'工作,它满足作为覆盖。看看这个[我以前的答案](http://stackoverflow.com/questions/14441619/actual-difference-in-implementing-overriding-using-abstractproperty-and-abstra/14441682#14441682)关于如何ABC检查覆盖。 –