<div dir="ltr"><div dir="ltr">BTW:<div><br></div><div><div><font face="monospace, monospace">In [7]: issubclass(set, frozenset)</font></div><div><font face="monospace, monospace">Out[7]: False</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [8]: issubclass(frozenset, set)</font></div><font face="monospace, monospace">Out[8]: False</font><br><br>no reason to do anything different here.<br><br></div><div>and:</div><br><font face="monospace, monospace">In [13]: issubclass(MappingProxyType, abc.Hashable)<br>Out[13]: False</font><div><br></div><div>so yes, there is a need for something different</div><div><br></div><div>-CHB</div><div><br></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 11, 2018 at 12:34 PM, Chris Barker <span dir="ltr"><<a href="mailto:chris.barker@noaa.gov" target="_blank">chris.barker@noaa.gov</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 class="gmail_extra"><div class="gmail_quote"><span class="">On Thu, Oct 11, 2018 at 9:54 AM, Jonathan Fine <span dir="ltr"><<a href="mailto:jfine2358@gmail.com" target="_blank">jfine2358@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Summary: Long post. Because of LSP, neither dict nor frozendict are a<br>
subclass of the other.</blockquote><div><br></div></span><div>given Python's dynamic typing, these issues are kinda academic :-)</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>> Intuition tells me that a frozen dictionary is a form of dictionary<br>
> that adds restrictions, not that a dictionary is a frozen dictionary<br>
> that you left out to thaw.<br></span></blockquote><div><br></div></span><div>well, IIUC the Liskov principle correctly then a subclass is never a version of a class that does less, but rather always one that does more.</div><div><br></div><div>Think you intuition may be driven by the choice of names and history: yes, a frozen dict sounds like a regular dict that has been altered (specifically frozen) -- but if we called them "hash_table" and "mutable_has_table", then your intuition may be different :-)</div><div><br></div><div>As for subclassing or not, for most Python code is makes no difference -- polymorphism is not achieved through subclassing. and the "Pythonic" way to test for type is through ABCs, and we already have Mapping and MutableMapping, which kind of surprised me, as there is no builtin Mapping that isn't also a MutableMapping.</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Notice that I said USEFUL property P. The negation Q of property P is<br>
also a property.</blockquote><div><br></div></span><div>well, yeah, but I think the concept of "useful" is pretty vague.</div><div><br></div><div>in this case, is "imutablilty" the "useful" property -- or is "hashability"?, which would want us to use abc.Hashable.</div><div><br></div><div>So:</div><div><br></div><div>I don't care what is or isn't a subclass of what -- I don't think that's a Pythonic question. But I do think :</div><div><br></div><font face="monospace, monospace">issubclass(frozendict, abc.Mapping) and issubclass(frozendict, abc.Hashable)</font><div><br></div><div>would be useful.</div><div><br></div><div>BTW, I just noticed that:</div><div><br></div><div>A tuple, as in ``issubclass(x, (A, B, ...))``, may be given as the target to check against. This is equivalent to ``issubclass(x, A) or issubclass(x, B) or ...`` etc.
</div><div><br></div><div>which seems less useful than "and" -- at least for ABCs</div><div><br></div><div>I suppose that API pre-dates ABCs....</div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">One way to fix this in Python 4 would be to create a common ancestor,<br>
which has only the shared methods of dict and frozendict.</blockquote><div><br></div></span><div>which would be an immutable, but not hashable, mapping ?!? </div><span class=""><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Or do<br>
something similar with abstract base classes.<br></blockquote><div><br></div></span><div>already done -- see above.</div><div><br></div><div>-CHB</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_7464050683262466801gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div>