I myself found out abotu this restriction once I clashesd into it-
soit was one time
the restriction bit me back.
But I can't remember if that was for intended production code or for
toying around
either.
Anyway, a simple "nop" function can allow for any arbitrary expression
to be used
as
Hello,
Le 2017-09-16 à 07:22, Serhiy Storchaka a écrit :
> 16.09.17 12:39, Larry Hastings пише:
>> So why don't decorators allow arbitrary expressions? [...]
>
> Actually I remember somebody raised this question a year or two ago,> but
> don't remember details.
The discussion I remember
It was and is all very intentional. I don't want to encourage line noise,
which the at-sign already resembles. But namespacing and some form of
parametrization (i.e. calls) are essential. So that's what we got.
On Sep 16, 2017 11:30 AM, "Skip Montanaro" wrote:
> >
> Indeed, I can’t remember a single time where I’ve needed that, let alone
actually realized the restriction existed.
Likewise. I suspect the use of a function sort of just fell out from the
pre-decorator usage. Things like staticmethod()
I always realized the restriction was there, and once in a while mention it
in teaching. But I've NEVER had an actual desire to use anything other that
a simple decorator or a "decorator factory" (which I realize is a decorator
in the grammar, but it's worth teaching how to parameterize custom
On Sep 16, 2017, at 02:39, Larry Hastings wrote:
> I'm not proposing that we allow arbitrary expressions as decorators... well,
> I'm not doing that yet at least. But like I said, the syntax has been this
> way for 13 years and I don't recall anybody complaining.
Indeed,
On 16 September 2017 at 21:22, Serhiy Storchaka wrote:
> Actually I remember somebody raised this question a year or two ago, but
> don't remember details.
Aye, I remember that as well, but apparently the thread title for the
discussion was sufficiently unrelated to the
16.09.17 12:39, Larry Hastings пише:
So why don't decorators allow arbitrary expressions? The PEP discusses
the syntax for decorators, but that whole debate only concerned itself
with where the decorator goes relative to "def", and what funny
punctuation might it use. It never says
The syntax for decorators in the grammar is quite specific:
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
Decorators can be either a dotted name, or a dotted name followed by
arguments. This disallows:
@mapping['async'] # looking something up in a mapping
@func(1, 2,