[Python-Dev] PEP 318: Order of operations

Ka-Ping Yee python-dev at zesty.ca
Tue Mar 30 06:33:45 EST 2004


Referring back to this example:

> It all fits together beautifully.
>
>     def func(arg, arg) [optimized, classmethod]:
>         .author = 'Sir Galahad'
>         .version = 42
>         """Description."""
>         code
>         more code

These syntax decisions work well together because they make it
visually obvious what is going to happen in what order.

        first do this       then this   then this
              |                 |           |
              v                 |           |
    .--------------------.      v           v
    | def func(arg, arg) | [optimized, classmethod]:
    |                    '---------.
    |     .author = 'Sir Galahad'  |
    |     .version = 42            |
    |     """Description."""       |
    |     code                     |
    |     more code                |
    '------------------------------'

First, the function is defined with the attributes set in it;
then the decorators are applied from left to right.  That's good
because it lets us set attributes that pass information to
decorators, as in Paul's examples:

    def foo(self) [spark]:
        .spark_rule = 'DOC := HEAD BODY FOOT'

    def foo(self) [publish_to_web]:
        .url = '/cgi-bin/directory/directory'


-- ?!ng



More information about the Python-Dev mailing list