[Python-3000] my take on "typeclasses"

Paul Moore p.f.moore at gmail.com
Thu May 11 17:36:14 CEST 2006


On 5/11/06, Bill Birch <birchb at tpg.com.au> wrote:
> On Thu, 11 May 2006 12:38 am, you wrote:
> > On 5/10/06, Bill Birch <birchb at tpg.com.au> wrote:
> > > A simple test to see where your thinking is at. Consider:
[...]
> > Clearly False - D() is not an object of type I1.
> >
> > Of course, whether isinstance() is actually a useful way of checking
> > depends on what you're trying to discover. It's very rare that I'd
> > care about the actual class inheritance structure of an object. What I
> > care about is whether I can *use* it like an I1. And that's not
> > decidable (it includes semantic considerations), so no builtin can
> > answer that question for me.
> >
> > Hence, I document my expectations, and trust my caller to follow the
> > documentation. We're all consenting adults, and all that... (Note:
> > This is ideal documentation, not real-life, you understand :-))
> >
> > So where does that put my thinking?
> >
> Hmmmm. You would -really- prefer a predicate which return True, something
> which predicts usability. The closest is a structural type equivalence test
> which compares the signatures of the object and the interface:

No. I told you what I think. The code as written should return False,
and I don't believe code can determine semantic issues, so it
shouldn't try.

"You would -really- prefer a predicate which return True" - No. As
it's not possible to get this (in the same absolute sense that it
isn't possible to solve the halting problem) I don't want something
that attempts to - I'd still have to deal with the places where it's
wrong, so I don't want to start down that route.

I don't *want* a predicate that returns anything in particular. I
don't code in a way that would need such a predicate.

>    I1.conforms(obj)
>
> Because the type in question is an Interface it uses a structural type check
> which sees that D() does conform to the interface.  And returns True. So as
> far as the Interface is concerned it -is- looks like an instance an I1.

Structural type checks, inheritance checks, whatever. None of them
avoid the need to document the semantic requirements. So I'd rather
rely on documented expectations, and a consenting adults philosophy.

Which is not to say that I can't see cases where isinstance,
type-based dispatching, interfaces/adaptation or any other type-based
process could be useful. It's just that for the code I write, it's
never been necessary.

Paul.


More information about the Python-3000 mailing list