[Python-ideas] Adding "+" and "+=" operators to dict

Rob Cliffe rob.cliffe at btinternet.com
Fri Feb 13 23:28:47 CET 2015


On 13/02/2015 04:40, Stephen J. Turnbull wrote:
> Donald Stufft writes:
>
>   > Python often gets little improvements that on their own are not
>   > major enhancements but when looked at cumulatively they add up to a
>   > nicer to use language. An example would be set literals, set(["a",
>   > "b"]) wasn't confusing nor was it particularly hard to use, however
>   > being able to type {"a", "b"} is nice, slightly easier, and just
>   > makes the language jsut a little bit better.
>
> Yes, yes, and yes.
>
>   > Similarly doing:
>   >
>   >     new_dict = dict1.copy()
>   >     new_dict.update(dict2)
>   >
>   > Isn't confusing or particularly hard to use, however being able to
>   > type that as new_dict = dict1 + dict2 is more succinct, cleaner,
>   > and just a little bit nicer.
>
> Yes, no, and no.
>
> Succint?  Yes.  Just count characters or lines (but both are
> deprecated practices in juding Python style).
>
> Cleaner?  No.  The syntax is cleaner (way fewer explicit operations),
> but the semantics are muddier for me.  At one time or another, at
> least four different interpretations of "dict addition" have been
> proposed already:
There are many features of the languages where decisions have had to be 
made one way or another.  Once the decision is made, it's unfair to say 
the semantics are muddy because they could have been different.
Rob Cliffe


More information about the Python-ideas mailing list