A decorator syntax not yet mentioned (I think!)

P

Paul Rubin

Roman Suzi said:
Bingo!

Just replace decorate with "from" and the nice syntax is found:

def f:
staticmethod
grammarrule('statement : expression')
version("Added in 2.4")
deprecatedmethod
type_(None)
from self, p:
"""docstring here"""
print p[1]

You can get rid of the keyword:
def f:
staticmethod
grammarrule('statement : expression')
version("Added in 2.4")
deprecatedmethod
type_(None)
(self, p):
"""docstring here"""
print p[1]

The syntax is if you see f without parentheses, what follows is decorators.
The outdent before the arg list makes it obvious where the arg list is.
 
M

Mark Bottjer

Peter said:
I understand that. What I don't understand is why you make
this complaint about the indented form, when the non-indented
form with @decorator has exactly the same issue! In all
cases, pre-def is weird in that the declarative lines that
decorate the function lead to action *after* the def is
closed, whether the decorators are indented or not.

I *do* have the same complaint about the @decorator form. *All* the
prefix forms have this problem. That's why I don't like them as much as
the "top of function block" forms; at least with those we have the
already-established pattern of docstrings to help us understand what is
going on. The "in-statement with def" forms are the cleanest
conceptually, but just don't seem to code up well.

My point was only that I find the indented block of decorators to be
less intuitive than the (ugly, but to me more obvious) flush-left list
of @decorators. If we're going to be stuck with a prefix form, I like
@dec better than decorate: (though "meta dec" would be fine as well).

I think GvR's point about not having to look inside the function to
determine its specification is nice in theory, but we're already used to
doing exactly that. Changing it now just adds confusion.

-- Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top