[Python-ideas] dict '+' operator and slicing support for pop

George Sakkis george.sakkis at gmail.com
Tue Mar 17 19:26:44 CET 2009


On Tue, Mar 17, 2009 at 2:14 PM, Chris Rebert <pyideas at rebertia.com> wrote:
> On Tue, Mar 17, 2009 at 10:58 AM, Ka-Ping Yee <python at zesty.ca> wrote:
>> On Tue, 17 Mar 2009, Josiah Carlson wrote:
>>
>>> On Tue, Mar 17, 2009 at 9:03 AM, George Sakkis <george.sakkis at gmail.com>
>>> wrote:
>>>>
>>>> On Tue, Mar 17, 2009 at 11:00 AM, Andrii V. Mishkovskyi
>>>> <mishok13 at gmail.com> wrote:
>>>>
>>>>> 1. Add ability to use '+' operator for dicts
>>>>>
>>>
>>> Both of the ideas suffer from "+ is no longer commutative", which
>>> sort-of bothers me.
>>
>> I don't find that a convincing argument, since + is not commutative
>> for lists or tuples either.  Andrii's original proposal is the most
>> natural interpretation -- notice that if x and y are dicts:
>>
>>    dict(x.items()) gives x
>>
>>    dict(x.items() + y.items()) gives x + y
>>
>> That looks perfectly consistent to me.
>>
>> George's counter-proposal doesn't make sense to me at all -- it
>> messes up the types of all the values in the dict.  And it's
>> inconsistent with the built-in behaviour of + with other types:
>> it doesn't add lists element-by-element, so it shouldn't add
>> dicts element-by-element either.
>
> Not to put words into people's mouths, but it seems like the concern
> was really less over the non-commutativity and move over the fact that
> data from the first dict gets silently clobbered by the second dict;
> whereas in the list, tuple, and string cases, no data is ever lost in
> the process.

Just to be clear, I'm between -0.5 and -1 to the whole idea; my
counter-proposal was simply meant to point out the potential ambiguity
in semantics and the fact that the original proposal silently loses
data.

George



More information about the Python-ideas mailing list