Proposal: named return values through dict initialization and unpacking

MRAB python at mrabarnett.plus.com
Tue Jun 21 14:08:28 EDT 2016


On 2016-06-21 18:12, Terry Reedy wrote:
> 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
>
The thread was titled "Unpacking a dict" and it started on 25 May 2016.




More information about the Python-list mailing list