1. Python Enhancement Proposals, PEP 318 – Decorators for Functions and Methods: The section titled "Decorators with Arguments" explicitly describes this pattern. It states that an expression like @A(x) is evaluated as func = A(x)(func). This requires A(x) to be a callable that returns the actual decorator. The provided code follows this exact structure. (Source: https://peps.python.org/pep-0318/)
2. The Python 3 Language Reference, Section 8.7. Function definitions: This official documentation details the decorator syntax. It clarifies that for a decorator expression like @v(a, b, c), the evaluation is equivalent to f = v(a, b, c)(f). This confirms that the outer function is called with the arguments first, and its return value is then applied as the decorator. (Source: https://docs.python.org/3/reference/compoundstmts.html#function-definitions)
3. Stanford University, CS41: The Python Programming Language, Course Notes: In the lecture notes covering decorators, the section on "Decorators with Arguments" explains that to pass arguments to a decorator, "you need to have a function that takes those arguments and returns a decorator." This describes the factory pattern shown in the question's code. (Source: Stanford University, CS41 Course Reader, "Decorators")