<div dir="ltr"><div><br></div><div>May be the following simple prototype of frozendict could be useful?<br></div><div><br></div><div style="margin-left: 40px;"><span style="font-family: courier new, monospace;">def frozen_error():<br>   return RuntimeError("frozendict is not mutable")<br><br>class frozendict(dict):<br>    #<br>    def __setitem__(self, key, val):<br>        raise frozen_error()<br>    #<br>    def setdefault(self, key, val=None):<br>        raise frozen_error()<br>    #<br>    def update(self, ob):<br>        raise frozen_error()<br>    #<br>    def pop(self):<br>        raise frozen_error()<br>    #<br>    def popitem(self, ob):<br>        raise frozen_error()<br>    #<br>    def clear(self, ob):<br>        raise frozen_error()<br>    #<br>    def __delitem__(self, key):<br>        raise frozen_error()<br>    #<br>    def __repr__(self):<br>        return "frozendict(" + dict.__repr__(self)[1:-1] + ")"<br>    #<br>    def __str__(self):<br>        return "frozendict(" + dict.__str__(self)[1:-1] + ")"<br>    #<br>    def fromkeys(self, keys, val=None):<br>        return frozendict([(key,val) for key in keys])<br>    #<br>    def copy(self):<br>        return frozendict(self.items())<br></span></div>        <br>среда, 10 октября 2018 г., 20:06:03 UTC+3 пользователь Philip Martin написал:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><div dir="ltr">Hi, I first want to thank everyone in the community for the contributions over the years. I know the idea of a frozendict has been proposed before and rejected. I have a use case for a frozendict implementation that to my knowledge was not discussed during previous debates. My reasoning for a frozendict class stems from patterns I typically see arise when performing ETL or data integrations and conversions. I generally have used MappingProxyType as a way to set default mapping to a function or to set an empty mapping to a function. I've created a gist with an example use case:<div><br></div><div><a href="https://gist.github.com/pmart123/493edf84d9aa61691ca7321325ebb6ab" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpmart123%2F493edf84d9aa61691ca7321325ebb6ab\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHph_mRlX2XuEwJSvjPa7mnywGtYA';return true;" onclick="this.href='https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fpmart123%2F493edf84d9aa61691ca7321325ebb6ab\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHph_mRlX2XuEwJSvjPa7mnywGtYA';return true;">https://gist.github.com/<wbr>pmart123/<wbr>493edf84d9aa61691ca7321325ebb6<wbr>ab</a><br></div><div><br></div><div>I've included an example of what code typically looks like when using MappingProxyType and what it could look like with a frozendict implementation. I believe this use case may also be under-reported in open source code as it often crops up when integrating third-party data sources, which at times can't be open sourced due to licensing issues. I would love to hear if anyone has used MappingProxyType in a similar manner, or if this use case could help warrant a frozendict in the standard library.</div></div></div>
</blockquote></div>