PEP318 alternate syntax idea
Jim Jewett
JimJJewett at yahoo.com
Tue Mar 23 14:39:05 EST 2004
Stephen Horne <steve at ninereeds.fsnet.co.uk> wrote in message news:<vb0060pr3pqqa9a539l6ld9oehkngi03vg at 4ax.com>...
> ... if decorators really catch on, there could be cases where
> they are applied repeatedly to many functions, and
> possibly with many decorators.
> ... [Could we move the redundant lists to a single preamble]
> how about...
> def [staticmethod, ...] :
> # could use alternate keyword such as 'decorate'
> def a (a1, a2) :
> "this function is decorated"
> ...
> def b (b1, b2) :
> "this function is also decorated"
> ...
> def c (c1, c2) :
> "this function is _not_ decorated"
> ...
This was soundly rejected. I liked the idea myself, until
Phillip Eby explained what I was missing.
In python,
block_starter:
indented_code1
indented_code2
implies something about the how the *indented* code will be run.
It may get skipped (if/else), repeated (for/while) or delayed
(class, def), but it will definately do something strange.
With decorators, the function definition itself is normal (and
therefore should not be indented); it is the decorators that
run at an unexpected time.
using:
decorator1
decorator2
decorator3
def a (args):
pass
may still be an option, but it doesn't answer your request for a
*single* preamble. I agree that creating a lambda *just* to bundle
the decorators is ugly, but if you really have a large number of
decorators that always go together ... maybe there is a good name
for the collection.
-jJ
More information about the Python-list
mailing list