add type predicates to types module?

Paul Moore paul.moore at uk.origin-it.com
Fri Apr 9 08:18:27 EDT 1999


On Sat, 3 Apr 1999 10:59:36 +0200, M.-A. Lemburg <mal at lemburg.com> wrote:
>Jeremy Hylton wrote:
>> 
>> The folkloric "file-like object" type is a good example.  When people
>> say "file-like object" they mean an object that responds in a
>> reasonable way to the particular subset of methods on a builtin file
>> object that they are interested in.

Er, doesn't this point out one of the inherent flaws with this scheme? You
don't really want to know the type of the item, you want to be able to do
certain things with it. So why not do

	try:
	    whatever...
	except TypeError:
	    whatever you do if you're given the wrong type

In other words, try and trap exceptions rather than test beforehand.

That tends to be how C++ "generic programming" works. Write templates using
the operations you need - the templates won't compile when used with incorrect
types. We're just replacing a compile time check with a runtime one, because
Python uses dynamic typing in place of C++'s static model.

Paul Moore.





More information about the Python-list mailing list