On Thu, Oct 11, 2018 at 3:35 PM, Steven D'Aprano <st...@pearwood.info>
wrote:

> On Thu, Oct 11, 2018 at 12:34:13PM -0700, Chris Barker via Python-ideas
> wrote:
>
> > 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 :
> >
> > issubclass(frozendict, abc.Mapping) and issubclass(frozendict,
> abc.Hashable)
> >
> > would be useful.
>
> So you do care about what is and isn't a subclass :-)
>

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.

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:

hasinterface(an_object, (ABC1, ABC2, ABC3))

Even though, it would be the same as issubclass() (though I'd like an AND
relationship with the tuple of ABCs..)

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.


> It is 2018 and we've had isinstance and issubclass in the language since
> Python 2.2 in 2002, I really wish that we could get away from the idea
> that checking types is unPythonic and duck-typing is the One True Way to
> do things. The old, Python 1.5 form of type-checking:
>
>     type(spam) is dict
>
> was not so great, since it tested only for a specific type by identity.
> But with ABCs and virtual subclasses and inheritance, isinstance is a
> great way to check that your duck both quacks and swims, rather than
> watching it sink and drown in the middle of your function :-)
>

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.

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 :-)

And actually, if you're talking "modern" Python, isn't static type checking
the way to do it now ?

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?

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

chris.bar...@noaa.gov
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to