[issue36553] inspect.is_decorator_call(frame)
Sylvain Marie
report at bugs.python.org
Thu Oct 10 10:46:24 EDT 2019
Sylvain Marie <sylvain.marie at schneider-electric.com> added the comment:
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`.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36553>
_______________________________________
More information about the Python-bugs-list
mailing list