[Python-ideas] values in vs. values out

Ron Adam rrr at ronadam.com
Thu Jan 13 23:56:20 CET 2011

On 01/13/2011 01:41 PM, Ian Bicking wrote:
> On Thu, Jan 13, 2011 at 8:30 AM, Luc Goossens
> <luc.goossens at cern.ch
> <mailto: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.

I think what you're thinking of is a single function signature object that 
can be passed around as is.  In essence, it separates the signature 
handling parts of a function out into a separate object.  The tricky part 
is making it easy to get to from inside the function.

    def foo(a, b, c=3) >> foosig:
       return bar(foosig)           # No packing or unpacking here!

    result = foo(*args, **kwds)
    (a, b) = result.args
    c = result.kwds['c']



Ron A.

More information about the Python-ideas mailing list