why not add an identity function to the builtins?

@noop(buttons[0].clicked.connect)
def foo():
  ... # do whatever

On 2020-02-03 9:08 p.m., Guido van Rossum wrote:
I’ve always resisted changing this, but it keeps coming up, and in other cases we don’t restrict the grammar (except when there are real ambiguities). So maybe the SC can accept a PRP for this?

On Mon, Feb 3, 2020 at 15:47 Ben Avrahami <avrahami....@gmail.com <mailto:avrahami....@gmail.com>> wrote:

    Hi all, decorators are a very powerful feature in python, but it's
    syntax is strangely restrictive.

    decorator ::=  "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE

    for 99% of cases this is not a hindrance, but sometimes we'd
    rather be able to use full expression syntax. consider the
    following example (using PyQt):

        # make 10 buttons
        buttons = [QPushButton(f'button #{i}') for i in range(10)]
        # for now we only want to bind an event to the first button
        @buttons[0].clicked.connect
        def foo():
            ... # do whatever

    in cases such as this, it would be useful to have any expression
    acceptable as a decorator.

    In addition to other use cases such as chained function calling
    (@buttons_dict.get("foo"). clicked.connect), the restrictiveness
    of the decorator syntax seems like a strange oversight. Arbitrary
    expressions are already allowed in decorator lines as arguments,
    so allowing them as the called decorator shouldn't be too difficult.

    Any thoughts on this?
    _______________________________________________
    Python-ideas mailing list -- python-ideas@python.org
    <mailto:python-ideas@python.org>
    To unsubscribe send an email to python-ideas-le...@python.org
    <mailto:python-ideas-le...@python.org>
    https://mail.python.org/mailman3/lists/python-ideas.python.org/
    Message archived at
    
https://mail.python.org/archives/list/python-ideas@python.org/message/WOWD4P323DYDIGUQVWMESDWUG6QOW4MP/
    Code of Conduct: http://python.org/psf/codeofconduct/

--
--Guido (mobile)

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FKE7ZFGUDCU5WVOE2QTD5XGMCNCOMETV/
Code of Conduct: http://python.org/psf/codeofconduct/

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/VZKMMXMBKC3MAYXYIWPNVE6Z23L4W2MJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to