This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maggyero
Recipients bob.ippolito, exarkun, gvanrossum, j1m, maggyero, mwh, rhettinger
Date 2019-06-07.14:05:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1559916315.57.0.952678742799.issue37196@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-06-07 14:05:15maggyerosetrecipients: + maggyero, mwh, gvanrossum, rhettinger, bob.ippolito, exarkun, j1m
2019-06-07 14:05:15maggyerosetmessageid: <1559916315.57.0.952678742799.issue37196@roundup.psfhosted.org>
2019-06-07 14:05:15maggyerolinkissue37196 messages
2019-06-07 14:05:15maggyerocreate