[Python-Dev] Why aren't decorators just expressions?
Joao S. O. Bueno
jsbueno at python.org.br
Tue Sep 19 02:57:43 EDT 2017
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
Anyway, a simple "nop" function can allow for any arbitrary expression
to be used
as decorator, at expense of a little more line noise. And the
restriction prevents the line
noise to emerge as "cool" in some framework that mitg take inspiration
in trends ongoing
in other languages.
nop = lambda f: f
@nop(MyClass(things)[dimension1, dimension2[subdimension5]] +
def my_func(): pass
On 18 September 2017 at 18:33, Éric Araujo <merwok at netwok.org> wrote:
> 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 was https://bugs.python.org/issue19660
> Guido said: «Nobody has posted a real use case. All the examples are
> toys. What are the real use cases that are blocked by this? Readability
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/jsbueno%40python.org.br
More information about the Python-Dev