<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 21, 2019 at 7:45 AM Antoine Pitrou <<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>> wrote:<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 5 Mar 2019 16:39:40 +0900<br>
INADA Naoki <<a href="mailto:songofacandy@gmail.com" target="_blank">songofacandy@gmail.com</a>><br>
wrote:<br>
> I think some people in favor of PEP 584 just want<br>
> single expression for merging dicts without in-place update.<br>
> <br>
> But I feel it's abuse of operator overload.  I think functions<br>
> and methods are better than operator unless the operator<br>
> has good math metaphor, or very frequently used as concatenate<br>
> strings.<br>
> <br>
> This is why function and methods are better:<br>
> <br>
> * Easy to search.<br>
> * Name can describe it's behavior better than abused operator.<br>
> * Simpler lookup behavior. (e.g. subclass and __iadd__)<br>
> <br>
> Then, I propose `dict.merge` method.  It is outer-place version<br>
> of `dict.update`, but accepts multiple dicts.  (dict.update()<br>
> can be updated to accept multiple dicts, but it's not out of scope).<br>
> <br>
> * d = d1.merge(d2)  # d = d1.copy(); d.update(d2)<br>
<br>
One should also be able to write `d = dict.merge(d1, d2, ...)`<br>
<br>
If dict merging is important enough to get a new spelling, then I think<br>
this proposal is the best: explicit, unambiguous, immediately<br>
understandable and easy to remember.<br></blockquote><div><br></div><div>I don't find it easy to understand or remember that d1.update(d2) modifies d1 in place, while d1.merge(d2) first copies d1.</div><div><br></div><div>Maybe the name can indicate the copying stronger? Like we did with sorting: l.sort() sorts in-place, while sorted(l) returns a sorted copy.<br></div></div><br>-- <br><div dir="ltr" class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div></div>