J2 decorator grammar

Steven Bethard steven.bethard at gmail.com
Mon Aug 23 20:28:39 CEST 2004

Robert Brewer <fumanchu <at> amor.org> writes:
> with:
>     classmethod
>     .author = "François Pinard"
> def foo(cls):
>     pass
> def bar():
>     pass
> with bar:
>     staticmethod
>     .version = "0.2.4"
> with:
>     .name = "New Item"
> thing = Item()
> with thing:
>     .color = "red"

The "with" syntax seems pretty reasonable for functions -- probably worth 
changing the proposal's:

Should not be a word with a planned future. This rules out "with" and "as".

to something like:

Should not be a word with a planned future of different semantics.  This rules 
out "as", and perhaps "with" (but see [link to this discussion]).

I have to say that I'm not a big fan of the implicit object of "with" for 
anything but defs.  "Explicit is better than implicit" being the rule, I don't 
see that we gain much by allowing implicit "with" objects for expressions in 
general -- the last example above is a little hard for me to read.

However, because funcdefs and classdefs are not expressions, but still might 
be reasonable objects of a "with" clause, I can see that a special syntax for 
these cases might be merited.

Just my two pfennings...


More information about the Python-list mailing list