Re: Observations about types

Guido van Rossum (Guido.van.Rossum@cwi.nl)
Mon, 10 Aug 1992 23:57:02 +0200

>On another noter: I was trying to do some reasonable type checking in
>some routines I was writing for a stress test harnass. The problem is
>that type() only returns the generic type, not the specific type. I.e.
>if I have an instance of class 'foo', type(instance) will say <type
>'instance'>, but not <type 'instance foo'> or so.

True, but for class instances you can access the "secret" attribute
__class__ to get at the class.

For many other purposes of type checking you also need much more
information than what type() returns; e.g. in many situations tuples
of different length should be considered different types, and the
types of the items should be considered as well. Luckily it isn't too
hard to write a function that returns a unique string with the
required properties -- type() is just a low-level tool to be used by
such a function.

--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"I told you. We're an anarcho-syndicalist commune."