<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 11, 2018 at 3:35 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Oct 11, 2018 at 12:34:13PM -0700, Chris Barker via Python-ideas wrote:<br>
<br>
> I don't care what is or isn't a subclass of what -- I don't think that's a<br>
> Pythonic question. But I do think :<br>
> <br>
> issubclass(frozendict, abc.Mapping) and issubclass(frozendict, abc.Hashable)<br>
> <br>
> would be useful.<br>
<br>
</span>So you do care about what is and isn't a subclass :-)<br></blockquote><div><br></div><div>well, kinda -- I don't care whether dict and frozen dict have a subclassing relationship, and I don't care what class a given object is that gets passed to my code. What I *might* care about is what interface it presents, which is what ABCs are for.</div><div><br></div><div>If Python had a way to check ABCs without issubclass, then I wouldn't care about subclasses at all. I'd actually kind of like to have:</div><div><br></div><div><font face="monospace, monospace">hasinterface(an_object, (ABC1, ABC2, ABC3))</font></div><div><br></div><div>Even though, it would be the same as issubclass() (though I'd like an AND relationship with the tuple of ABCs..)</div><div><br></div><div>Maybe I'm making a distinction that isn't really there, but I see a subclass of an ABC is quite different than a subclass of another concrete class.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It is 2018 and we've had isinstance and issubclass in the language since <br>
Python 2.2 in 2002, I really wish that we could get away from the idea <br>
that checking types is unPythonic and duck-typing is the One True Way to <br>
do things. The old, Python 1.5 form of type-checking:<br>
<br>
    type(spam) is dict<br>
<br>
was not so great, since it tested only for a specific type by identity. <br>
But with ABCs and virtual subclasses and inheritance, isinstance is a <br>
great way to check that your duck both quacks and swims, rather than <br>
watching it sink and drown in the middle of your function :-)<br></blockquote><div><br></div><div>yeah, I'm not so sure -- I"ve been watching Python go more and more in that direction -- and I don't think I'm happy about it.</div><div><br></div><div>Personally, the only time I check a type is the darn list-of-strings vs single-string issue -- ever since we got true_division, that's the only type error I commonly see (that isn't trivial to debug). And I still wish Python had a Character type, and then I wouldn't need to do that either :-)</div><div><br></div><div>And actually, if you're talking "modern" Python, isn't static type checking the way to do it now ?</div><div><br></div><div>Now that I think about it - how does MyPy/Typeshed handle the iterable_of_strings problem? Since a single string IS and iterable of strings?</div><div><br></div><div>-CHB</div><div><br></div></div><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></div>