Make 'def' and 'class' usable within expressions

Joe Mason joe at notcharles.ca
Thu Mar 25 20:46:45 CET 2004


In article <mailman.405.1080228996.742.python-list at python.org>, Thomas Heller wrote:
> BTW, how would you specify base classes for ICustomer?
> 
>     ICustomer = Interface(class, IBaseInterface):
>         def get_id():
>             """Return the customer ID"""

Oh, right, that points up another inconsistency in the syntax I wanted
to point out: it really should be

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

Otherwise, how do we pass multiple to the function?

    PairOfClasses = Interfaces(class: pass, class: pass)

The PEP318 decorators doesn't support this, of course, but it doesn't
pretend to.  This syntax looks like just a regular function call which
should allow multiple parameters, though.

You could say that only the last parameter of a function call can be a
def or class expression, which then gets bound to the next definiton
found.  But what about

    if (class):

That's an expression too.  Does the : bind to the embedded class or the
if?

Can of worms.

In a C-delimeted language, embedding a large {...} sequence inside a
function call would be awkward, but not deadly.  Here, I think Python's
delimiting has defeated you.

Joe



More information about the Python-list mailing list