Type checking in python?

Paul Prescod paul at prescod.net
Thu Jul 20 11:05:02 EDT 2000


Samuel Scarano wrote:
> 
> First of all, are you referring to something specific by "Unicode strings"?
> (I wasn't aware of any standard unicode string class but I'd be interested
> if there is one.)

Python 1.6/2 has a Unicode string class.

> Anyway, interesting point, but isn't that what multiple inheritance is for?
> A static (or, for that matter, dynamic) typecheck ensuring that the function
> is called with a string would work fine with unicode strings as long as the
> unicode string class is a subclass of the string class.

This is a matter of long and ongoing debate in the object oriented
languages world. I think that the currently dominant view among those
who think deeply about it is that you inherit because you want some
"free methods" from a parent class and that is a totally different
operation from saying you want to act like that class.

C++ has a concept of "private inheritance" which is really inheritance
without subclassing. And you could have empty base classes to kludge
subclassing without inheritance. (so there is some distinction but it
isn't really clear in the language). You could call this type
inheritance without implementation inheritance also.

Java also takes a middle of the road stance. It allows type type
inheritance without implementation inheritance through interfaces but a
lot of important "interfaces" are defined as classes. From a purity
point of view it would be better if they were just interfaces.

A language called Sather makes the distinction clear and principled:
http://www.gnu.org/software/sather/ICSI_Sather/Documentation/EclecticTutorial/node5.html

Where Python would/should come down on these issues is an open question.

-- 
 Paul Prescod - Not encumbered by corporate consensus
"Hardly anything more unwelcome can befall a scientific writer than 
having the foundations of his edifice shaken after the work is 
finished.  I have been placed in this position by a letter from 
Mr. Bertrand Russell..." 
 - Frege, Appendix of Basic Laws of Arithmetic (of Russell's Paradox)




More information about the Python-list mailing list