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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com