[Python-3000] my take on "typeclasses"

Paul Moore p.f.moore at gmail.com
Wed May 10 16:38:49 CEST 2006


On 5/10/06, Bill Birch <birchb at tpg.com.au> wrote:
> A simple test to see where your thinking is at. Consider:
[...]
> The manual for isinstance() says: "return true if classinfo is a type object
> and object is an object of that type". So consider this:
>
>          isinstance( D(), I1 )
>
> Is this True or False?

(Making obvious assumptions about the syntax that isn't "real" Python...)

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?

Paul.


More information about the Python-3000 mailing list