[Python-ideas] PEP: Dict addition and subtraction

Rhodri James rhodri at kynesim.co.uk
Thu Mar 21 09:01:55 EDT 2019

On 21/03/2019 11:34, Antoine Pitrou wrote:
> On Wed, 20 Mar 2019 15:46:24 -1000
> Christopher Barker <pythonchb at gmail.com>
> wrote:
>>> This is precisely why I worded my question this way: what has changed
>>> in the last 20 years that make a "+" dict operator more compelling
>>> today than it was?  Do we merge dicts much more frequently than we
>>> did?
>> The analogy doesn't hold because @ was a new operator -- a MUCH bigger
>> change than dimply defining the use of + (or | ) for dicts.
> But it's less disruptive when reading code, because "x @ y" is
> unambiguous: it's a matrix multiplication.  "x + y" can be many
> different things, and now it can be one more thing.

"x @ y" is unambiguous once you know what it means.  Until then, it's 
just mysterious.

>> I wouldn't mind the new operator if its meaning was clear-cut.  But
>>> here we have potential for confusion, both for writers and readers of
>>> code.
>> but it's NOT a new operator, it is making use of an existing one, and sure
>> you could guess at a couple meanings, but the merge one is probably one of
>> the most obvious to guess, and one quick test and you know -- I really
>> can't see it being a ongoing source of confusion.
> Did you actually read what I said?  The problem is not to understand
> what dict.__add__ does.  It's to understand what code using the +
> operator does, without knowing upfront whether the inputs are dicts.

Welcome to polymorphism.

Rhodri James *-* Kynesim Ltd

More information about the Python-ideas mailing list