[Python-ideas] Syntactic sugar to declare partial functions

Stefan Behnel stefan_ml at behnel.de
Mon Aug 13 13:46:49 EDT 2018


Michel Desmoulin schrieb am 09.08.2018 um 18:59:
> I'd rather have functools.partial() to be added as a new method on
> function objects.
> 
>> from functools import partial
>>
>> def add(x:int,y:int)->int:
>>     returnx +y
>>
>> add_2 = partial(add,2)
> 
> Would become:
> 
> add_2 = add.partial(2)

Except that this only works for functions, not for other callables.
Meaning, code that uses this for anything but its self-defined functions
will break as soon as someone passes in a callable object that is not a
function.

Stefan



More information about the Python-ideas mailing list