[Python-ideas] PEP: Dict addition and subtraction

Antoine Pitrou solipsis at pitrou.net
Thu Mar 21 07:34:37 EDT 2019


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.

> 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.

Regards

Antoine.




More information about the Python-ideas mailing list