osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposal: named return values through dict initialization and unpacking


On 6/21/2016 3:34 AM, Ari Freund via Python-list wrote:
> I'd like to run this idea by the community to see if it's PEP worthy and
> hasn't been already rejected.
>
> Background
> Just as keyword arguments enhance code readability and diminish the risk of
> bugs, so too would named
> return values.  Currently, we can write
>    val1, val2, val3 = myfunc()
> but we must take care to order the variables correctly, i.e., in the same
> order as the corresponding
> values in myfunc's return statement.  Getting it wrong may result in
> difficult-to-detect bugs.  This
> problem would be alleviated if we could name the return values and
> disregard their order.
>
> My proposal consists of two parts.
>
> 1.  Add a new form of assignment by dictionary unpacking.

There was a recent (last couple of months?) discussion on python-ideas 
about dictionary unpacking.  It does not seem too practical.  But maybe 
you can find the thread

-- 
Terry Jan Reedy