Meta decorator with parameters, defined in explicit functions

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Wed Jun 29 22:50:15 EDT 2016


On Tuesday, June 28, 2016 at 5:03:08 PM UTC+12, Ben Finney wrote:
>     decorator_with_args = lambda decorator: lambda *args, **kwargs: lambda func: decorator(func, *args, **kwargs)

Ah, I see why there are 3 lambdas, instead of 2. It’s so that you can write

    decorator_func = decorator_with_args(actual_func)

then you can use it like this:

    @decorator_func(...additional args for actual_func...)
    def some_func...

to invoke actual_func(some_func, ... additional args for actual_func...) on some_func, and assign the result back to some_func.



More information about the Python-list mailing list