Meta decorator with parameters, defined in explicit functions

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Sun Jul 3 19:25:27 EDT 2016


On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote:
> Sorry, but you're the one who doesn't seem to get it. Because it's a
> decorator, "your" function is replacing the caller's function in the
> caller's namespace.

No it is not. The replacement happens here:

        def generated_decorator(func) :
            return \
                decorator(func, *args, **kwargs)
        #end generated_decorator

As you can see, the function being called, “decorator”, is supplied by the caller. The function being decorated, “func”, is supplied by the caller (along with the additional *args and **kwargs). And the returned function is returned *as-is*, so whatever docstring was assigned by the caller is *NOT* “clobbered”.

Once again, the only docstrings I am setting are the ones for functions that *I* generate.

Do you understand that yet?



More information about the Python-list mailing list