[Python-Dev] can't assign to function call

Hrvoje Niksic hrvoje.niksic at avl.com
Mon Mar 18 17:36:17 CET 2013


On 03/18/2013 04:40 PM, Steven D'Aprano wrote:
>> In analogy with that, Python could implement what looks like assignment to function call like this:
>>
>> val = f(arg)          # val = f.__call__(arg)
>> f(arg) = val          # f.__setcall__(arg, val)
>
> That's all very well, but what would it do? It's not enough to say
 > that the syntax could exist, we also need to have semantics.

I am not the best person to answer because I go on to argue that this 
syntax is not needed in Python at all (anything it can do can be 
implemented with __setitem__ at no loss of clarity).  Still, if such a 
feature existed in Python, I imagine people would use it to set the same 
resource that the function obtains, where such a thing is applicable.

> Aside: I'd reverse the order of the arg, val in any such hypothetical
 > __setcall__, so as to support functions with zero or more arguments:
>
> f(*args, **kwargs) = val  <=>  f.__setcall__(val, *args, **kwargs)

That would be a better design, I agree.



More information about the Python-Dev mailing list