New submission from Darren Dale <dsdal...@gmail.com>: I posted a suggestion at python-ideas that the declaration of abstract properties could be improved in such a way that they could be declared with either the long-form or decorator syntax using the built-in property and abc.abstractmethod:
{{{ class MyProperty(property): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) for f in (self.fget, self.fset, self.fdel): if getattr(f, '__isabstractmethod__', False): self.__isabstractmethod__ = True break class C(metaclass=ABCMeta): @MyProperty @abstractmethod def x(self): pass @x.setter @abstractmethod def x(self, val): pass # this syntax would also be supported: #@abstractmethod #def getx(self): # pass #@abstractmethod #def setx(self, val): # pass #x = MyProperty(getx, setx) class D(C): 'D does not define a concrete setter and cannot be instantiated' @C.x.setter def x(self): return 1 class E(D): 'E has a concrete getter and setter, and can be instantiated' @D.x.setter def x(self, val): pass }}} It is hopefully evident that a relatively minor extension can be made to the built-in property such that @abstractproperty would no longer be needed. I have prepared a patch, complete with documentation and unit tests, but unfortunately I have not been able to test it because I have not been able to build Python from a mercurial checkout on either Ubuntu 11.04 or OS X 10.6.6 (for reasons unrelated to the patch.) BDFL thought the idea sounded good for inclusion in Python-3.3, and requested I submit the patch here. ---------- components: Library (Lib) files: property_with_abstractmethod.patch keywords: patch messages: 131436 nosy: dsdale24 priority: normal severity: normal status: open title: Improving property to accept abstract methods type: feature request versions: Python 3.3 Added file: http://bugs.python.org/file21293/property_with_abstractmethod.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11610> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com