<div dir="ltr"><div class="gmail_extra">I've implemented `frozendict` a few times for various projects and never knew about MappingProxyType.  I always used `collections.abc.Mapping` ...</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 9:12 AM, David Mertz <span dir="ltr"><<a href="mailto:mertz@gnosis.cx" target="_blank">mertz@gnosis.cx</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">The difference in hits might be because MappingProxyType has a funny name and is in a hidden-ish location.  I.e. not necessarily because it *would be* less used or useful if it were more exposed.<div><br></div></div></blockquote><div><br></div><div>It also might be because you can use `frozenset` in python2.x code -- And there's lots of that lying around...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>In either case, the name that makes sense to me would be `frozendict`.  That could very well live in `collections` of course.<br></div></div></blockquote><div><br></div><div>Yes, I agree.  Though it'd also probably need to be hashable if we were to give it that name.  I'm not 100% sure that `MappingProxyType` works there as it's just a view into another mapping.  If the first mapping changes, so does the hash.  This is the same problem we have hashing tuple in some sense -- But tuple can say "Nope, sorry.  I can't hash this because it's got an unhashable member".  I don't think we can really do the same thing with a MappingProxy since most of the time, it'll be constructed from something else.  I suppose the workaround is pretty simple though:</div><div><br></div><div>class frozendict(MappingProxyType):</div><div>    def __init__(self, proxy):<br>        super().__init__(proxy.copy())  # Copy the proxy! -- Maybe need `copy.copy()` instead?<br></div><div>    def __hash__(self):<br>        return hash(frozenset(self.items()))</div><div><br></div><div>This could likely be done better, but hopefully it gets the idea across...</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Feb 28, 2017 at 7:40 AM, Ivan Levkivskyi <span dir="ltr"><<a href="mailto:levkivskyi@gmail.com" target="_blank">levkivskyi@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"><div><div>Searching MappingProxyType on GitHub gives over 10,000 results.<br>I think it probably makes sense to make mappingproxy more "visible",<br>maybe move it to collections module? (where OrderedDict lives)<br><br></div>I am not sure if it makes sense to move it to builtins. (for comparison frozenset gives around 1000,000 results)<br><br>--<br></div>Ivan <br><div><div><br><br></div></div></div><div class="m_-9196022794170621541HOEnZb"><div class="m_-9196022794170621541h5"><div class="gmail_extra"><br><div class="gmail_quote">On 28 February 2017 at 16:24, Joseph Hackman <span dir="ltr"><<a href="mailto:josephhackman@gmail.com" target="_blank">josephhackman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1<br>
<br>
I think this makes a lot of sense. What would you name the built in?<br>
<span class="m_-9196022794170621541m_-6159540040656993137HOEnZb"><font color="#888888"><br>
-Joseph<br>
</font></span><div class="m_-9196022794170621541m_-6159540040656993137HOEnZb"><div class="m_-9196022794170621541m_-6159540040656993137h5"><br>
> On Feb 28, 2017, at 7:17 AM, Michel Desmoulin <<a href="mailto:desmoulinmichel@gmail.com" target="_blank">desmoulinmichel@gmail.com</a>> wrote:<br>
><br>
> We have the immutable frozenset for sets and and tuples for lists.<br>
><br>
> But we also have something to manipulate dict as immutable datastructures:<br>
><br>
>>>> from types import MappingProxyType as idict<br>
>>>> d = idict({'a':1, 'b':2, 'c':3})<br>
>>>> d['a'] = 4<br>
> Traceback (most recent call last):<br>
>  File "<ipython-input-3-c6f93d6278af<wbr>>", line 1, in <module><br>
>    d['a'] = 4<br>
> TypeError: 'mappingproxy' object does not support item assignment<br>
><br>
> We could expose this as a built type to allow the last of the most<br>
> important data structure in Python to be easily immutable.<br>
><br>
> ______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_-9196022794170621541gmail_signature" data-smartmail="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</font></span></div></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></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></div>