<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Mon, May 29, 2017 at 5:06 PM Matt Gilson <<a href="mailto:matt@getpattern.com">matt@getpattern.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 29, 2017 at 11:59 AM, Neil Girdhar <span dir="ltr"><<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">A long time ago, I proposed that the dict variants (sorteddict, defaultdict, weakkeydict, etc.) be made more discoverable by having them specified as keyword arguments and I got the same feedback that the poster here is getting.  Now, instead of moving these classes into dict, why not have a factory like<div><br></div><div>dict.factory(values=None, *, ordered=True, sorted=False, has_default=False, weak_keys=False, weak_values=False, …)</div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Hmm ... I don't think that I like this.  For one, it greatly increases the amount of surface area that needs to be maintained in the standard library.  As far as I know, we don't currently have a OrderedWeakKeyDictionary with defaultdict behavior.  If this was to be added, then each of the combinations of input keyword arguments would need to be supported.  Many of them probably don't have very compelling use-cases or they might not have semantics that would be easy to agree upon a "preferred behavior" (Assuming that a mythological SortedDict pops into existence in the standard lib, what happens if you call `dict.factory(sorted=True, ordered=True)`?).  Of course, this sets a precedence that future dict subclasses need to be added to the `dict.factory` constructor as well which risks a very bloated signature (or, someone has to make the decision about which subclasses should be available and which should be left off ...).  This last argument can repurposed against providing easy access to builtin dict subclasses via their own methods (`dict.defaultdict(...)`).</div></div></div></div></blockquote><div><br></div><div>You can just raise NotImplementedError for the bad combinations and the reasonable combinations that aren't implemented yet. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>I don't find very cumbersome to import the dict subclasses that I need from the locations where they live.  I like that it forces me to be explicit and I think that it generally makes reading the code easier in the normal cases (`defaultdict(in)` vs. `dict.factory(default=int)`).  Of course, if someone finds this idea particularly interesting, they could definitely explore the idea more by creating a package on pypi that attempts to provide this factory function.  If it got usage, that might go a long way to convincing us nay-sayers that this idea has legs :-).</div></div></div></div></blockquote><div><br></div><div>Fair enough.  The reason I had proposed it was to make the various dict incantations more discoverable.  Also, I was using a lot of weak-key dictionaries and it was odd to me that there was no ordered version of weak key dictionaries, etc.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>If prefers the keyword-argument as options to the keyword-argument as initializer magic, they can set:</div><div><br></div><div>dict = dict.factory</div><div><br></div><div>Best,</div><div><br></div><div>Neil</div><div><div><span> <br>On Thursday, March 9, 2017 at 5:58:43 PM UTC-5, Chris Barker wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div><span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>If we really want to make defaultdict feel more "builtin" (and I don't see<br>
>any reason to do so), I'd suggest adding a factory function:<br>
><br>
>dict.defaultdict(int)<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Nice.<br></blockquote><div><br></div><div>I agree -- what about:</div><div><br></div><div>dict.sorteddict() ??</div><div><br></div><div>make easy access to various built-in dict variations...</div><div><br></div><div>-CHB</div><div><br></div></div><div><br></div>-- <br></span><div><span><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            <a href="tel:(206)%20526-6959" value="+12065266959" target="_blank">(206) 526-6959</a>   voice<br>7600 Sand Point Way NE   <a href="tel:(206)%20526-6329" value="+12065266329" target="_blank">(206) 526-6329</a>   fax<br>Seattle, WA  98115       <a href="tel:(206)%20526-6317" value="+12065266317" target="_blank">(206) 526-6317</a>   main reception<br><br></span><a rel="nofollow">Chris....@noaa.gov</a></div>
</div></div>
</blockquote></div></div></div><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>
<br></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><br><br clear="all"><div><br></div>-- <br><div class="m_4792584331402632359gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><span><p dir="ltr" style="line-height:1.656;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10pt;font-family:Arial;vertical-align:baseline;white-space:pre-wrap"><font color="#000000">Matt Gilson </font></span><span style="font-size:10pt;font-family:Arial;color:rgb(153,153,153);vertical-align:baseline;white-space:pre-wrap">| </span><span style="font-size:10pt;font-family:Arial;color:rgb(0,0,0);vertical-align:baseline;white-space:pre-wrap">Pattern</span></p><p style="line-height:1.656;margin-top:0pt;margin-bottom:0pt"><font color="#000000" face="Arial"><span style="font-size:13.3333px;white-space:pre-wrap">Software Engineer</span></font></p><a href="https://www.getpattern.com?utm_source=email&utm_medium=email&utm_campaign=signature-matt" style="text-decoration:none" target="_blank"><span style="font-size:9pt;font-family:Arial;color:rgb(17,85,204);text-decoration:underline;vertical-align:baseline;white-space:pre-wrap">getpattern.com</span></a></span><br></div></div></div></div>
</div></div></blockquote></div></div>