J2 decorator grammar

Robert Brewer fumanchu at amor.org
Mon Aug 23 19:18:45 CEST 2004

François Pinard wrote:
> [Peter Maas]
> > Robert Brewer schrieb:
> > with:
> >     return ...
> >     accept ...
> >     classmethod
> > def func():
> >     <function body>
> > "using" instead of "with" would be equally satisfactory for me. I
> > don't like "decorate" because it sounds like "attaching some bells
> > and whistles" or "making it look pretty" which isn't 
> adequate for the
> > meaning of this syntax.
> I'm not especially crusading for `with', but it has the 
> advantage that it will
> likely become a keyword in some later version of Python, and 
> likely also,
> will be used in `with SOMETHING:' and not barely as `with:'.

That's a very interesting point. I hadn't noticed the similarity between decorator suites and "with" suites before. I could be argued that decorator suites are a case of a with-suite where the referent is implied. That is:

def foo(cls):


with foo:
def foo(cls):

If this is a strong implication, then we could make the argument that decorator suites should allow arbitrary targets, not just def. In that case, a decorator suite which did not possess a signifier ("with:") could universally imply that the referent (the target, that which is signified) follows the suite. Therefore, future use-cases might allow all of the following:

    .author = "François Pinard"
def foo(cls):

def bar():
with bar:
    .version = "0.2.4"

    .name = "New Item"
thing = Item()
with thing:
    .color = "red"

Definitely cool. But too big, I think, for the proposal at this point. That's a large-enough topic that it's probably best to leave to Guido's gut feelings right now. It's enough to point out that such futures are possible; at most, we might mention that "with" and decorators are semantically similar, so we shouldn't reject "with" out-of-hand.

Robert Brewer
Amor Ministries
fumanchu at amor.org

More information about the Python-list mailing list