New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing arbitrary expressions in the @expression syntax #81377
Comments
Could we allow arbitrary expressions in the @expression syntax for applying decorators to functions/classes? The current grammar restriction to:
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:
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 |
The syntax is deliberately limited. The reasons are explained at: https://www.python.org/dev/peps/pep-0318/#current-syntax |
@christian Heimes
Yes I read that. But I am wondering if after 15 years Guido still has this "gut feeling". Because my gut feeling as a Python *user* who has discovered decorators and stumbled on this restriction was: "what?!". |
What you want to write is as unreadable as it ever was. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: