
Hi Eric (and Rob, and Ben, ...), Sorry maybe this was not clear from my mail but I am not so much interested in possible work-arounds but in why this asymmetry exists in the first place. I mean is there a reason as to why it is the way it is, or is it just that nobody ever asked for anything else. cheers, Luc On Jan 13, 2011, at 4:00 PM, Eric Smith wrote:
On 01/13/2011 09:30 AM, Luc Goossens wrote:
Hi all,
There's a striking asymmetry between the wonderful flexibility in passing values into functions (positional args, keyword args, default values, *args, **kwargs, ...) and the limited options for processing the return values (assignment). Hence, whenever I upgrade a function with a new keyword arg and a default value, I do not have to change any of the existing calls, whereas whenever I add a new element to its output tuple, I find myself chasing all existing code to upgrade the corresponding assignments with an additional (unused) variable. So I was wondering whether this was ever discussed before (and recorded) inside the Python community. (naively what seems to be missing is the ability to use the assignment machinery that binds functions' formal params to the given actual param list also in the context of a return value assignment)
You can achieve something similar with PEP 3132's Extended Iterable Unpacking:
def f(): return 0, 1, 2, 3 ... a, b, c, d, *unused = f() a, b, c, d, unused (0, 1, 2, 3, [])
If you add more return values, they show up in unused.
def f(): return 0, 1, 2, 3, 4 ... a, b, c, d, *unused = f() # note caller is unchanged a, b, c, d, unused (0, 1, 2, 3, [4])
Or you could return dicts.
Eric.
_______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas