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`. |