[Python-Dev] A usability argument for list-after-def

Gregory Lielens gregory.lielens at fft.be
Thu Aug 5 23:52:26 CEST 2004


> Of the options on the Wiki page ( at 
> http://www.python.org/moin/PythonDecorators ), this seems to 
> leave only 
> list-after-def, the previous community favorite and the first PEP 318 
> syntax to have been implemented.
> 
> Guido's principal argument against list-after-def, if I 
> recall correctly, 
> was that it is ugly when multiple or lengthy decorators are 
> involved.  But, 
> "ugly" isn't an argument any more, so that shouldn't rule out 
> list-after-def.  :)

On a cosmetic point of view, I also prefer the list-after-def syntax,
first time I saw it it was the one than seemed the easiest (the "def f()
as [decorator]" variant was event clearer, but the argument that as is
only for renaming has mitigaed that somewhat ;-) )
"Cosmetic" does not sound like a very convincing argument, but I feel
that this whole discussion is purely on a cosmetic level anyway, it is
just a way to express more clearly something that is already
possible...and as feedback as been asked for... ;-)

But does it means that the list-after-def behaves like all lists, so
that these are possible and equivalent?

def foo() [decorator1, decorator2(bar)]:
   ...

def foo() [
    decorator1, 
    decorator2(bar)]:
   ...

my_complex_decorator=[decorator1, decorator2(bar)]
def foo() my_complex_decorator :
   ...

If it is, I am +1 on list-after-def (and, because of the last example,
+2 on a variant with a keyword or pseudo-keyword between the def and the
list, like ("with" is only an example) :

def foo() with [decorator1, decorator2(bar)]:
   ... 
my_complex_decorator=[decorator1, decorator2(bar)]
def foo() with my_complex_decorator :
   ...
def foo2() with my_complex_decorator :
   ...


If not (i.e. the brackets are just a syntax hint), I am -1, I prefer the
the pie syntax cause it would break consistency with other lists
usage...
For example, 
  for j in [1,2]:
    ...
  for j in ["a","b",
	       1,2,3,4]:
     ...
  for j in mylist:
     ...
are all possible, so it would be very surprising if the def syntax would
not be similar, it would mean that the brackets after a def are not
really a list and that would feel too much like special-casing to me...

Best regards,

Greg.




More information about the Python-Dev mailing list