New submission from Géry <gery.o...@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 <rep...@bugs.python.org> <https://bugs.python.org/issue37196> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com