For future readers wondering what the fuss is about, in older versions of Python, the decorator syntax was restricted to identifier expressions possibly containing attribute access . and up to one call () at the end.
Of course, the call could always contain arbitrary expressions as arguments, which made it easy to sneak in arbitrary decorator expressions via an identity function.
def me(x):
return x
@me(lambda f: print("hi"))
def add(a, b):
return a + b
For future readers wondering what the fuss is about, in older versions of Python, the decorator syntax was restricted to identifier expressions possibly containing attribute access
.
and up to one call()
at the end.Of course, the call could always contain arbitrary expressions as arguments, which made it easy to sneak in arbitrary decorator expressions via an identity function.
This was the topic of one of my StackOverflow answers.