The official doc of the partial function from the functools stdlib module says 
it "is used for partial function application which “freezes” some portion of a 
function’s arguments and/or keywords resulting in a new object with a 
simplified signature".

However, whereas positional arguments are effectively "frozen" (cannot be 
altered in the partial object), keyword arguments can in fact not be frozen as 
they always will be overridden by the ones passed to the partial object.

The "and/or keywords" part in the quote above thus sounds wrong when applied to 
the current implementation, and is more accurately describing the following 
situation :

def partial(func, /, *args, **keywords):
    def newfunc(*fargs, **fkeywords):
        return func(*args, *fargs, **keywords, **fkeywords)   # instead of the 
current func(*args, *fargs, **{**keywords, **fkeywords}) value 
    newfunc.func = func
    newfunc.args = args
    newfunc.keywords = keywords
    return newfunc

Shouldn't we provide the above implementation - which really freezes the given 
positional AND keyword arguments - in a new partial function to be added to the 
functools module, and fix the docs accordingly ?

On the signature side, we would also actually always get a "new object with a 
simplified signature" as stated in the doc, which is not the case currently.
If we consider the following code :

    import functools
    def F(arg, opt = 'BaseValue') :
        return (arg, opt)
    G = functools.partial(F, opt = 'NewValue')

the partial function G's signature is (arg, opt = 'NewValue') and is not really 
simplified compared to the initial (arg, opt = 'BaseValue') one.
The only effect of partial on the function signature is to alter the default 
values of the specified keyword arguments.

With the proposed implementation, the signature would actually be simplified to 
(arg).
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/PGTY2IH4YKS2HO3IGN7P3TPQ6VZ6ZZJG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to