Make 'def' and 'class' usable within expressions

Shane Hathaway shane at zope.com
Thu Mar 25 10:57:49 EST 2004


Thomas Heller wrote:
> Shane Hathaway <shane at zope.com> writes:
>>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.

Guido said that he'd like the "staticmethod" declaration to be closer to 
the first argument, since it changes the meaning of the first argument. 
  The syntax I'm proposing lets you do that.  (I didn't introduce the 
method of specifying parameters until now, though.)

foo = staticmethod(def(a, b=25)):
     obj = Bar(a, b)
     obj.stuff()
     return obj

> BTW, how would you specify base classes for ICustomer?
> 
>     ICustomer = Interface(class, IBaseInterface):
>         def get_id():
>             """Return the customer ID"""

That would be the appropriate way to do it, assuming that Interface is 
not a metaclass.

Shane




More information about the Python-list mailing list