[Python-ideas] decorator syntax limitation
Franck Michea
franck.michea at gmail.com
Thu Feb 20 22:31:45 CET 2014
Hi there,
Today I hit a limitation of decorator syntax, and I was wondering if
maybe this limitation could be removed, or if they could allow more.
The grammar for decorators is[1]:
decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE
But `dotted_name` doesn't allow to write things like the comment put in
the snippet attached, or this smaller snippet:
@M(b).decorator()
def wrapped_func():
pass
Although it looks possible to me to add this syntax, I was wondering
if it had been discussed previously, and if I could see that
discussion.
All discussions I found were a lot older, arround the time decorators
were designed and the syntax was being choosen. I also read PEP306 and
PEP318.
This is not a blocking issue since you can do with a temporary
variable, but I was wondering what were your thoughts on this.
Thank you very much,
[1]: http://docs.python.org/3.3/reference/grammar.html
===== Snippet ==========
class foo_decorator:
def __init__(self):
pass
def __call__(self, func):
return func
class Foo:
def test(self):
return foo_decorator()
class Bar:
def __init__(self):
self._foo = Foo()
def M(val):
return val._foo
b = Bar()
# SyntaxError: @M(b).test()
m = M(b)
@m.test()
def func():
print('Hello World!')
func()
========================
--
Franck Michea - EPITA/LSE/GISTRE 2014
More information about the Python-ideas
mailing list