[Python-Dev] PEP 318 - generality of list; restrictions on elements

Anders J. Munch andersjm at dancontrol.dk
Tue Mar 9 05:36:25 EST 2004


"A.M. Kuchling" <amk at amk.ca> wrote:
> 
> def foo [static] (arg1, arg2): ...
> 
> (And personally I do, in fact, prefer the decorator-first syntax. because in
> the case of a long argument list that spanned multiple lines, the decorator
> would seem kind of lost.)

You think of the decorator expression as a simple expression, usually
just a single identifier, right?

Given that the decorator expression can be an arbitrary Python
expression, it _will_ be used as such. For example:

def foo(arg1, arg2) as release(
        version="1.0",
        author="me",
        status="Well I wrote it so it works, m'kay?",
        warning="You might want to use the Foo class instead"):

Reading code is pattern-matching. Placing the decorator in the middle
of the function-header breaks the usual function-header pattern. The
suffix notations allow the reader to pattern-match the classic
function header first using the skills aquired with unadorned code.

This is also why I believe the 'as' version is better than the bracket
version: In the the 'as' version the classic function header stands by
itself, so you can mentally parse that separately, whereas the bracket
version binds more closely with the argument list to form a single,
more complex pattern.  If the decorator is restricted to a single name
brackets are fine, but I don't think they will be.

If brackets win I think a space between the argument list and the
opening bracket should be recommended style.

- Anders





More information about the Python-Dev mailing list