Make 'def' and 'class' usable within expressions

Thomas Heller theller at python.net
Thu Mar 25 10:36:27 EST 2004


Shane Hathaway <shane at zope.com> writes:

> Thomas Heller wrote:
>> Shane Hathaway <shane at zope.com> writes:
>>>>    # Define an interface.
>>>>    ICustomer = Interface(class):
>>>>        def get_id():
>>>>            """Return the customer ID"""
>>>
>>>Today, this would be written as:
>>>
>>>     class ICustomer:
>>>         def get_id():
>>>             """Return the customer ID"""
>>>     ICustomer = Interface(ICustomer)
>> With PEP 318 in place, it would be written as:
>>       class ICustomer [Interface]:
>>           def get_id():
>>               """Return the customer ID"""
>> Hm.
>> I like the third way best.  Why? The 'Interface(class)' idiom
>> confuses
>> me.  But maybe I'm infected by the PEP 318 virus.
>
> What I don't like about the third alternative is the subtle
> distinction between parentheses and square brackets.  It seems like
> newbies would have a hard time with it, as would advanced programmers
> who are looking over a new code base.

That may be true, especially for classes.  But as understand it, the
main purpose of PEP 318 is for function decorators, not class
decorators.  And for functions it is clearer, since you always have a
parameter list.

BTW, how would you specify base classes for ICustomer?

    ICustomer = Interface(class, IBaseInterface):
        def get_id():
            """Return the customer ID"""

Thomas





More information about the Python-list mailing list