<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 21, 2019 at 1:54 PM Stefan Behnel <<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Steven D'Aprano schrieb am 21.03.19 um 17:21:<br>
> On Thu, Mar 21, 2019 at 09:11:18AM -0700, Guido van Rossum wrote:<br>
> <br>
>> I don't find it easy to understand or remember that d1.update(d2) modifies<br>
>> d1 in place, while d1.merge(d2) first copies d1.<br>
>><br>
>> Maybe the name can indicate the copying stronger? Like we did with sorting:<br>
>> l.sort() sorts in-place, while sorted(l) returns a sorted copy.<br>
> <br>
> How about dict.merged(*args, **kw)? Or dict.updated()?<br>
<br>
And then users would accidentally type<br>
<br>
  d.updated(items)<br>
<br>
and lack the tests to detect that this didn't do anything (except wasting<br>
some time and memory).<br>
<br>
Stefan<br></blockquote><div><br></div><div>Generally when I call a method named with a verb on an instance of something mutable, I expect it to do something on that instance and return None. So merged() or updated() feels more like a built-in or a function to import from somewhere, akin to sorted().<br></div><div><br></div><div>Perhaps dict.union(d2) could be considered? Three points in favor: 1) Not a verb, therefore makes it clearer that it returns something new. 2) Not confusable with existing dict methods. 3) It matches the name and behavior of set.union (modulo value conflicts), so will be easier to grok.<br></div></div></div>