implementing functools.partial that prepends additional arguments
Looking at the source code for _functoolsmodule.c
, I don't think there's much to worry about.
The module implementation of partial
handles pickling and repr
, but everything else looks like it works as in the documentation so presumably the reason it is implemented in C is just for efficiency. There is also the fact that it is a type rather than just being a function closure.
Note, however, that in the documentation example func
, args
, and keywords
are purely cosmetic; i.e. they are not overridable as they are with actual functools.partial
instances. One alternative would be to subclass functools.partial
:
class rpartial(partial):
def __call__(self, *args, **kwargs):
kw = self.keywords.copy()
kw.update(kwargs)
return self.func(*(args + self.args), **kw)