No, the function does not know where it is being called from or whom holds references to it.
At best you can access the parent calling frame (with sys._getframe(1)
), but that is not necessarily a decorator.
Generally, if your function needs access to a value from the calling frame, it is best to just pass it in. Have the roles
decorator call the wrapped function with an extra argument, for example.