<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"><span></span></div><div dir="ltr"><meta http-equiv="content-type" content="text/html; charset=utf-8"><div preoffsettop="10"><blockquote type="cite" __apple_fixed_attribute="true" preoffsettop="10"><font color="#000000"><span style="caret-color: rgb(0, 0, 0); background-color: rgba(255, 255, 255, 0);">On Mon, Mar 04, 2019 at 10:01:23AM -0500, James Lu wrote:<br><br></span></font></blockquote><blockquote type="cite" preoffsettop="118"><font color="#000000"><span style="caret-color: rgb(0, 0, 0); background-color: rgba(255, 255, 255, 0);">If you want to merge it without a KeyError, learn and use the more explicit {**d1, **d2} syntax.</span></font></blockquote></div><div dir="ltr">On Mar 4, 2019, at 10:25 AM, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><span>In your previous email, you said the {**d ...} syntax was implicit:</span><br><span></span><br><span>    In other words, explicit + is better than implicit {**, **#, unless </span><br><span>    explicitly suppressed.  Here + is explicit whereas {**, **} is </span><br><span>    implicitly allowing inclusive keys, and the KeyError is expressed </span><br><span>    suppressed by virtue of not using the {**, **} syntax.</span><br><span></span><br><span>It is difficult to take your "explicit/implicit" argument seriously when </span><br><span>you cannot even decided which is which.</span></div></blockquote>I misspoke. <br><div><span style="background-color: rgba(255, 255, 255, 0);"><blockquote type="cite">In your previous email, you said the {**d ...} syntax was implicit:<br><br>   In other words, explicit + is better than implicit {**, **#, unless <br>   explicitly suppressed.  Here + is explicit whereas {**, **} is <br>   implicitly allowing inclusive keys, and the KeyError is expressed <br>   suppressed by virtue of not using the {**, **} syntax.<br><br>It is difficult to take your "explicit/implicit" argument seriously when <br>you cannot even decided which is which.</blockquote></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Yes, + is explicit. {**, **} is implicit. </span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">My argument:</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">We should set the standard that + is for non-conflicting merge and {**, **} is for overriding merge. That standard should be so that + <i>explicitly asserts that the keys will not conflict </i>whereas {**d1, **d2} is ambiguous on why d2 is overriding d1.^</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">^Presumably you’re making a copy of d1 so why should d3 have d2 take priority? The syntax deserves a comment, perhaps explaining that items from d2 are newer in time or that the items in d1 are always nonces. </span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>The + acts as an implicit assertion and an opportunity to catch an invariant violation or data input error.</div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>Give me an example of a situation where you need a third dictionary from two existing dictionaries and having conflict where a key has a different value in both is desirable behavior. </div><div><br></div><div>The situation where non-conflicting merge is what’s desired is more common and in that case throwing an exception in the case of a conflicting value is a good thing, a way to catch code smell.</div></div></body></html>