<div dir="ltr">This discussion has my brain all twisted up...  I'm going to try to work my way through it to make some sense of what we're saying here.<div><ol><li>It is pretty easy to provide a subclass with a base `__missing__` implementation, so why should python be responsible for providing that behavior?</li><li>We don't want to encourage subclassing `dict`, so let's not make working with `__missing__` slightly nicer (see 1.)</li><li>Would adding `__missing__` to `dict` actually make working with it slightly nicer anyway?</li><li>Other places in the standard library for creating mappings easily (`UserDict` and `collections.Mapping`) do not support `__missing__``, but it is easy to build that functionality yourself (see 1. and example code below)<br></li></ol></div><div>Let me know if I left anything out or misrepresented any of the comments ... It definitely wasn't my intent.</div><div>As I see it, there are three paths forward.</div><div><br></div><div><ul><li>Do nothing.  The status quo probably only surprises one or two users a year, so lets not rock the boat.  Additionally, we can't add _everything_ everywhere.  Things just become a mess if you say "Yes" to every idea and you have to draw the line somewhere.<br></li><li>Add `__missing__` to `dict`.  It might be a simple pass-through method for raising `KeyError`, but hey, <a href="https://hg.python.org/cpython/file/tip/Objects/dictobject.c#l1723">maybe it'll simplify a code-path or two.</a><br></li><li>Add `__missing__` support to <a href="https://hg.python.org/cpython/file/tip/Lib/_collections_abc.py#l595">`collections.abc.Mapping`</a> (or I guess UserDict, but I'd be just as happy if that one went away completely :-).  I'm sure I haven't thought through all the pitfalls, but (additional documentation aside) it seems like it could be as easy as:<br></li></ul></div><div><br></div><div><br></div><font face="monospace, monospace">class Mapping(Sized, Iterable, Container):</font><div><font face="monospace, monospace">    def __missing__(self, key):</font></div><div><font face="monospace, monospace">        raise KeyError</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    @abc.abstractmethod</font></div><div><font face="monospace, monospace">    def __getitem__(self, key):</font></div><div><font face="monospace, monospace">        self.__missing__(key)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">    ... </font></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jul 5, 2016 at 3:19 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think this is a question for Raymond Hettinger.<br>
<div><div class="h5"><br>
On Tue, Jul 5, 2016 at 3:13 PM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com">mistersheik@gmail.com</a>> wrote:<br>
> Is it deprecated?<br>
><br>
> I've seen this question a lot on stackoverflow:<br>
> <a href="http://stackoverflow.com/questions/7148419/subclass-dict-userdict-dict-or-abc" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/7148419/subclass-dict-userdict-dict-or-abc</a><br>
> <a href="http://stackoverflow.com/questions/2390827/how-to-properly-subclass-dict-and-override-getitem-setitem" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/2390827/how-to-properly-subclass-dict-and-override-getitem-setitem</a><br>
> <a href="http://stackoverflow.com/questions/10901048/i-want-to-subclass-dict-and-set-default-values" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/10901048/i-want-to-subclass-dict-and-set-default-values</a><br>
> I still have no idea what the right answer is.<br>
><br>
> On Tue, Jul 5, 2016 at 6:11 PM Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>> wrote:<br>
>><br>
>> Because you shouldn't be using UserDict.<br>
>><br>
>> On Tue, Jul 5, 2016 at 3:07 PM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com">mistersheik@gmail.com</a>><br>
>> wrote:<br>
>> > Okay, that makes sense, but why isn't __missing__ in UserDict?<br>
>> ><br>
>> > On Tue, Jul 5, 2016 at 6:04 PM Guido van Rossum <<a href="mailto:guido@python.org">guido@python.org</a>><br>
>> > wrote:<br>
>> >><br>
>> >> What kind of question is that? If you subclass MutableMapping the<br>
>> >> whole feature doesn't exist (since you're not subclassing dict). It<br>
>> >> *only* exists for subclasses of dict.<br>
>> >><br>
>> >> On Tue, Jul 5, 2016 at 12:18 PM, Neil Girdhar <<a href="mailto:mistersheik@gmail.com">mistersheik@gmail.com</a>><br>
>> >> wrote:<br>
>> >> > But neither UserDict nor MutableMapping defines __missing__ ?  What<br>
>> >> > is a<br>
>> >> > subclasser supposed to do?<br>
>> >> ><br>
>> >> > On Wednesday, June 29, 2016 at 4:59:03 PM UTC-4, Guido van Rossum<br>
>> >> > wrote:<br>
>> >> >><br>
>> >> >> UserDict is superseded by MutableMapping.<br>
>> >> >><br>
>> >> >> I don't think we should make dict a kitchen sink class. I also don't<br>
>> >> >> think we should particularly encourage subclassing it. So -1 on<br>
>> >> >> adding<br>
>> >> >> dict.__missing__.<br>
>> >> >><br>
>> >> >> On Wed, Jun 29, 2016 at 12:30 PM, Ethan Furman <<a href="mailto:et...@stoneleaf.us">et...@stoneleaf.us</a>><br>
>> >> >> wrote:<br>
>> >> >> > On 06/29/2016 12:09 PM, Guido van Rossum wrote:<br>
>> >> >> ><br>
>> >> >> >> So providing the comprehensive base class is up to the user, not<br>
>> >> >> >> up<br>
>> >> >> >> to<br>
>> >> >> >> the stdlib. Is that such a big deal?<br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> > No, it's not.  But it makes for a better user experience if the<br>
>> >> >> > base<br>
>> >> >> > class<br>
>> >> >> > has the __missing__ method that raises a KeyError already.<br>
>> >> >> ><br>
>> >> >> > Didn't we add a UserDict that could be subclassed primarily<br>
>> >> >> > because<br>
>> >> >> > subclassing dict directly was such a poor user experience?<br>
>> >> >> ><br>
>> >> >> > If adding __missing__ to dict is huge (performance hit?), we don't<br>
>> >> >> > do<br>
>> >> >> > it.<br>
>> >> >> > If it's not, I think we should.  Maybe add it to UserDict if<br>
>> >> >> > performance<br>
>> >> >> > is<br>
>> >> >> > a concern?<br>
>> >> >> ><br>
>> >> >> ><br>
>> >> >> > --<br>
>> >> >> > ~Ethan~<br>
>> >> >> > _______________________________________________<br>
>> >> >> > Python-ideas mailing list<br>
>> >> >> > <a href="mailto:Python...@python.org">Python...@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>
>> >> >><br>
>> >> >><br>
>> >> >><br>
>> >> >> --<br>
>> >> >> --Guido van Rossum (<a href="http://python.org/~guido" rel="noreferrer" target="_blank">python.org/~guido</a>)<br>
>> >> >> _______________________________________________<br>
>> >> >> Python-ideas mailing list<br>
>> >> >> <a href="mailto:Python...@python.org">Python...@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>
>> >><br>
>> >><br>
>> >><br>
>> >> --<br>
>> >> --Guido van Rossum (<a href="http://python.org/~guido" rel="noreferrer" target="_blank">python.org/~guido</a>)<br>
>><br>
>><br>
>><br>
>> --<br>
>> --Guido van Rossum (<a href="http://python.org/~guido" rel="noreferrer" target="_blank">python.org/~guido</a>)<br>
<br>
<br>
<br>
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" rel="noreferrer" target="_blank">python.org/~guido</a>)<br>
_______________________________________________<br>
Python-ideas mailing list<br>
</div></div><a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<div class="HOEnZb"><div class="h5"><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>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:14.6667px;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"><img src="https://lh6.googleusercontent.com/KjKhxPuGD6aSETVh9dazBSiS5FGrt8b37DYQ6QZAxpJIomTEygFF6ygbgOUbR0MBzycO8-LF-FspB3wTJb8LXEfIbJ6lN4H2J04EYzOZg7uaG7YcGkWesdldHuXzhLwS-etJBGO6" width="95" height="26" style="border:none" alt="pattern-sig.png"></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.6667px;font-family:Arial;color:rgb(102,102,102);font-weight:700;vertical-align:baseline;white-space:pre-wrap">Matt Gilson</span><span style="font-size:10.6667px;font-family:Arial;color:rgb(102,102,102);vertical-align:baseline;white-space:pre-wrap"> // SOFTWARE ENGINEER</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.6667px;font-family:Arial;color:rgb(153,153,153);vertical-align:baseline;white-space:pre-wrap">E: </span><span style="font-size:10.6667px;font-family:Arial;color:rgb(17,85,204);vertical-align:baseline;white-space:pre-wrap"><a href="mailto:matt@getpattern.com" target="_blank">matt@getpattern.com</a></span><span style="font-size:10.6667px;font-family:Arial;color:rgb(153,153,153);vertical-align:baseline;white-space:pre-wrap"> // P: 603.892.7736</span></p><br><span style="font-size:12px;font-family:Arial;color:rgb(255,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent">We’re looking for beta testers.  Go </span><a href="https://www.getpattern.com/meetpattern" style="text-decoration:none" target="_blank"><span style="font-size:12px;font-family:Arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap;background-color:transparent">here</span></a><span style="font-size:12px;font-family:Arial;color:rgb(255,0,0);vertical-align:baseline;white-space:pre-wrap;background-color:transparent"> to sign up!</span></span><br></div></div>
</div>