[Python-ideas] Why operators are useful

Terry Reedy tjreedy at udel.edu
Sat Mar 16 19:13:04 EDT 2019

On 3/16/2019 8:01 AM, Gustavo Carneiro wrote:

> On Sat, 16 Mar 2019 at 10:33, Steven D'Aprano 
> <steve at pearwood.info 
> <mailto:steve at pearwood.info>> wrote:

>     The question this PEP is trying to answer is not "can we support every
>     use-case imaginable for a merge operator?" but "can we support the most
>     typical use-case?", which I believe is a version of:
>          new = a.copy()
>          new.update(b)
>          # do something with new

In my census of the stdlib, already posted and noted as subject to 
error, this was twice as common as all other non-update-in-place 
constructions (8 to 4) and about 1/4 as common as update in place (8 to 

> Already been said, but might have been forgotten, but the new proposed 
> syntax:
>      new = a + b
> has to compete with the already existing syntax:
>      new = {**a, **b}

Thank you and whoever mentioned it first on this thread.  I will look at 
using this in idlelib.  There is one place where .update is called 3 
times on the same initial dict in multiple lines.

> I wonder if this is only a matter of time, and over time programmers 
> will become more accustomed to "{**a, **b}"

I never paid this much attention as I did not know of any immediate use 
in my personal work (and there has not been yet) and I did not think 
about looking at idlelib.

Terry Jan Reedy

More information about the Python-ideas mailing list