Are there any “accepted” naming conventions for the innards of Python decorators?
The style guide doesn’t mention it, and this awesome entry about decorators is pretty consistent in using variants of “wrapped” for the ultimate function that is returned, but what about the names used when creating decorators that take arguments?
def decorator_name(whatevs):
def inner(function):
def wrapped(*args, **kwargs):
# sweet decorator goodness
return wrapped
return inner
Specifically, what are the conventions for inner, function, and wrapped in the above example?
There are no standardized conventions (such as PEPs) for those names. If you check the python stdlib you’ll find lots of different names for those functions.
However,
decoratoris a rather common name for the decorator functioninner.It is also common to call your
wrappedfunctionwrapperand decorate it withfunctools.wraps(f)withfbeing the wrapped function (funcis also a common name for it).