<div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Should our __sub__ behavior be the same...</blockquote><div><br></div><div>Sorry, our "__isub__" behavior. Long day... </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Mar 5, 2019 at 2:47 PM Brandt Bucher <<a href="mailto:brandtbucher@gmail.com">brandtbucher@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div> These semantics are intended to match those of <tt class="gmail-m_-1417922908329890845gmail-docutils gmail-m_-1417922908329890845gmail-literal">update</tt> as closely
as possible. For the dict built-in itself, calling <tt class="gmail-m_-1417922908329890845gmail-docutils gmail-m_-1417922908329890845gmail-literal">keys</tt> is
redundant as iteration over a dict iterates over its keys; but for
subclasses or other mappings, <tt class="gmail-m_-1417922908329890845gmail-docutils gmail-m_-1417922908329890845gmail-literal">update</tt> prefers to use the keys
method.</div><div> </div><div>The above paragraph may be inaccurate.
Although the dict docstring states that <tt class="gmail-m_-1417922908329890845gmail-docutils gmail-m_-1417922908329890845gmail-literal">keys</tt>
will be called if it exists, this does not seem to
be the case for dict subclasses.  Bug or feature?</div></blockquote><div><br></div><div style="margin-left:40px">>>> print(dict.update.__doc__)<br>D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.<br>If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]<br>If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v<br>In either case, this is followed by: for k in F:  D[k] = F[k]</div></div><div dir="ltr"><br></div><div>It's
 actually pretty interesting... and misleading/wrongish. It never says that keys is 
*called*... in reality, it just checks for the "keys" method before deciding whether to 
proceed with PyDict_Merge or PyDict<span class="gmail-m_-1417922908329890845gmail-pl-c1">_MergeFromSeq2</span>. It should really read more like:<br></div><div><br></div><div style="margin-left:40px">D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.<br>If E is present, has a .keys() method, and is a subclass of dict, then does:  for k in E: D[k] = E[k]<br>If E is present, has a .keys() method, and is not a subclass of dict, then does:  for k in E.keys(): D[k] = E[k]</div><div style="margin-left:40px">If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v</div><div style="margin-left:40px">In either case, this is followed by: for k in F:  D[k] = F[k]</div><div style="margin-left:40px"><br></div></div><div dir="ltr"><div>Should our __sub__ behavior be the same (i.e., iterate for dict subclasses and objects without "keys()", otherwise call "keys()" and iterate over that)? __iadd__ calls into this logic already. It seems to be the most "natural" solution here, if we desire behavior analogous to "update".<br></div><div><br></div><div>Brandt<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 1, 2019 at 8:26 AM Steven D'Aprano <<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Attached is a draft PEP on adding + and - operators to dict for <br>
discussion.<br>
<br>
This should probably go here:<br>
<br>
<a href="https://github.com/python/peps" rel="noreferrer" target="_blank">https://github.com/python/peps</a><br>
<br>
but due to technical difficulties at my end, I'm very limited in what I <br>
can do on Github (at least for now). If there's anyone who would like to <br>
co-author and/or help with the process, that will be appreciated.<br>
<br>
<br>
-- <br>
Steven<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>
</blockquote></div>