[Python-ideas] values in vs. values out

Ian Bicking ianb at colorstudy.com
Thu Jan 13 20:41:30 CET 2011

On Thu, Jan 13, 2011 at 8:30 AM, Luc Goossens <luc.goossens at cern.ch> wrote:

> 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)

I have often thought that I'd like a way to represent the arguments to a
function.  (args, kwargs) is what I usually use, but func(*thing[0],
**thing[1]) is very unsatisfying.  I'd like, um, func(***thing) ;)

Interestingly you have traditionally been able to do things like "def
func(a, (b, c))" (removed in py3, right?) -- but it created a sense of
symmetric between assignment and function signatures.  But of course keyword
arguments aren't quite the same (nor are named parameters, but I'll ignore
that).  So it would be neat if you could do:

(a, b, c=3) = func(...)

where this was essentially like:

result = func(...)
(a, b) = result.args
c = result.kwargs.get('c', 3)

Where result was some new tuple-dict hybrid object.

Ian Bicking  |  http://blog.ianbicking.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110113/4eb82fda/attachment.html>

More information about the Python-ideas mailing list