PEP 318 - Function Modifier Syntax

Duncan Booth duncan at NOSPAMrcp.co.uk
Mon Jun 9 10:31:32 EDT 2003


[posted and mailed]

Kevin Smith <Kevin.Smith at sas.com> wrote in news:20030609081617512-
0400 at braeburn.themorgue.org:

>     More generally, 
> 
>         def foo(self) as <tuple>:
>             perform method operation
> 
>     The proposed syntax is simple, powerful, easy to read, and 
>     therefore preserves those qualities of the Python language.

<tuple> should be <callable or tuple> to avoid requiring a trailing comma 
for the common case where only one function modifier is used. In fact it 
would probably be simpler just to allow any expression that evaluates 
either to a callable or an iterable, I don't see any particular reason to 
insist on it producing a tuple here.

In fact, I could see a good argument for treating these modifiers in much 
the same way as exceptions are handled (when matching an exception you can 
specify either an exception or a tuple of things that can match an 
exception).

        def foo(self) as <modifier>:
            perform method operation

where modifier is any expression resulting in a callable or a sequence of 
modifiers.

I think your PEP should put the proposal at the top and the discussion of 
rejected options should be further down in the rationale. I really thought 
you were proposing 'def classmethod foo(cls):...' until quite a long way 
through the proposal.

You need to say what order the modifiers are applied when there is more 
than one. Specifically is it left to right, or right to left?

I wonder what the implementation of this should be. Should the bytecode 
that is produced implement a loop over the modifiers directly, or should 
there be a new builtin that takes the function and the modifiers as 
arguments and the bytecode simply has to call the function and assign its 
result to the name? The second of these sounds as though it ought to be 
simpler to implement.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list