[New-bugs-announce] [issue37196] Allowing arbitrary expressions in the @expression syntax
Géry
report at bugs.python.org
Fri Jun 7 10:05:15 EDT 2019
New submission from Géry <gery.ogam at gmail.com>:
Could we allow arbitrary expressions in the @expression syntax for applying decorators to functions/classes? The current grammar restriction to:
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
is very surprising and I don't understand the real motivation.
I find it weird that you are not able to do that:
def f():
def g():
def h(x):
pass
return h
return g
@f()()
def i():
pass
since you get:
@f()()
^
SyntaxError: invalid syntax
but the following is perfectly valid:
def f():
def g():
def h(x):
pass
return h
return g
def g(x):
def h(x):
pass
return g
@g(f()())
def h():
pass
See this post for more details: https://stackoverflow.com/questions/56490579
----------
components: Interpreter Core
messages: 344939
nosy: bob.ippolito, exarkun, gvanrossum, j1m, maggyero, mwh, rhettinger
priority: normal
severity: normal
status: open
title: Allowing arbitrary expressions in the @expression syntax
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37196>
_______________________________________
More information about the New-bugs-announce
mailing list