J2 decorator grammar
Robert Brewer
fumanchu at amor.org
Mon Aug 23 13:18:45 EDT 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:
decorate:
classmethod
def foo(cls):
pass
implies
with foo:
classmethod
def foo(cls):
pass
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:
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"
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
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list