[Python-3000] PEP 3119 - Introducing Abstract Base Classes
Tony Lownds
tony at PageDNA.com
Fri Apr 27 20:17:41 CEST 2007
On Apr 27, 2007, at 10:40 AM, Bill Janssen wrote:
> Jim Jewett wrote:
>> On 4/27/07, Barry Warsaw <barry at python.org> wrote:
>>
>>> - - Attributes. Interfaces allow you to make assertions about
>>> attributes, not just methods, while ABCs necessarily cover only
>>> methods.
>>
>> Why can't they have data attributes as well?
>
> I agree with Jim. It seems to me that documenting standard attributes
> of a type is one thing that ABC's should be able to do. Perhaps a
> "@abstractattribute" decorator of some sort? Perhaps a class
> decorator
> "@attributes(name1, name2, ...)"? Attributes with those names
> would be
> automatically added to an instance, initialized to None, before the
> first __init__ method would be called.
+0 on abstract attributes. Methods seem to dominate most APIs that make
use of interfaces, but there are always a few exceptions.
Attribute annotations could provide an elegant solution here.
class ABC:
concrete_attribute : "any expression" = None
abstract_attribute : "any expression"
I posted about attribute annotations before on python-ideas and there
was
lukewarm response. If anyone thinks a PEP on attribute annotations is
worth
submitting, let me know.
Thanks
-Tony
More information about the Python-3000
mailing list