Support for using partial with positional only argument functions

Rather than adding a magical “PLACEHOLDER” sentinel value, another
common solution is to define a version of partial that binds from the
right rather than the left.

Here’s an untested implementation:

def partial_right(func, /, *args, **keywords):
    def newfunc(*fargs, **fkeywords):
        newkeywords = {**keywords, **fkeywords}
        return func(*fargs, *args, **newkeywords)
    newfunc.func = func
    newfunc.args = args
    newfunc.keywords = keywords
    return newfunc

It is a one line change from the code given in the docs:

https://docs.python.org/3/library/functools.html#functools.partial

I don’t think this is a very common need. As far as I can tell, none of
the major functional-programming languages that support partial
application provide the functionality. Although that might be because
their partial application are built on currying?

In any case, you are not the only one to request this sort of feature,
at least in the Javascript world:

3 Likes