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 smarie
Recipients smarie, yselivanov
Date 2019-10-10.14:46:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1570718784.89.0.760123357386.issue36553@roundup.psfhosted.org>
In-reply-to
Content
Quick update on this feature: for the following example to work:

from inspect import is_decorator_call

def set_hello_tag(tag='world'):
    if is_decorator_call():
        # called without parenthesis!
        # the decorated object is `tag`
        return set_hello_tag()(tag)   # note that `is_decorator_call` should not return True for this call
    else:
        def decorate(f):
            setattr(f, 'hello', tag)  # set a hello tag on the decorated f
            return f
        return decorate


Then `is_decorator_call` should be callable without arguments (default to current frame) and should return `True` only if the current frame is the one directly following decorator application. In nested frames (such as the one obtained after first recursive call to `set_hello_tag` above, `is_decorator_call` should return `False`.
History
Date User Action Args
2019-10-10 14:46:24smariesetrecipients: + smarie, yselivanov
2019-10-10 14:46:24smariesetmessageid: <1570718784.89.0.760123357386.issue36553@roundup.psfhosted.org>
2019-10-10 14:46:24smarielinkissue36553 messages
2019-10-10 14:46:24smariecreate