Make 'def' and 'class' usable within expressions
Thomas Heller
theller at python.net
Thu Mar 25 10:10:02 EST 2004
Shane Hathaway <shane at zope.com> writes:
> Ahem, I was hoping for opinions on this idea, either positive or
> negative. It could make Python better or worse. I need to know
> whether I should flesh out the proposal more.
>
> I've added some comparisons below. IMHO this syntax is clearer than
> the syntax proposed for PEP 318, and a little more powerful.
>
> Shane Hathaway wrote:
>> In thinking about PEP 318, I came across an idea that might be worth
>> pursuing further. It goes deeper than PEP 318, so it would need its
>> own PEP.
>> The idea is to make 'def' and 'class' usable within expressions.
>> Expressions using 'def' or 'class' are followed by a code block.
>> Upon evaluation of the expression, the 'def' or 'class' symbol
>> evaluates as the function or class created by the code block. Only
>> one 'def' or 'class' is allowed per expression.
>> # 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.
Thomas
More information about the Python-list
mailing list