Jonathan Fine wrote:
I also find writing decorators a bit
hard. It seems to be something I have to learn anew each time I do it.
Particularly for the pattern

@deco(arg1, arg2) def fn(arg3, arg4):
>     # function body

Perhaps doing something with partial might help here. Anyone here interested
in exploring this?


I can't think of a way that partial would help. But would
you find it easier if you could do something like this?

    class deco(Decorator):

        def __init__(self, arg1, arg2):
            self.arg1 = arg1
            self.arg2 = arg2

        def invoke(self, func, arg3, arg4):
            # function body

Implementation:

    class Decorator:

        def __call__(self, func):
            self._wrapped_function = func
            return self._wrapper

        def _wrapper(self, *args, **kwds):
            return self.invoke(self._wrapped_function, *args, **kwds)

--
Greg
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to