You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
1.4 KiB

From: paul.moore at uk.origin-it.com (Paul Moore)
Date: Fri, 9 Apr 1999 14:18:27 +0200
Subject: add type predicates to types module?
References: <cr1EjogB0KGWMPCmVY@holmes.parc.xerox.com> <14085.18842.492142.484721@bitdiddle.cnri.reston.va.us> <3705D878.4454DBEB@lemburg.com>
Message-ID: <slrn7grrvt.3vv6d11.paul.moore@ukrup480.rundc.uk.origin-it.com>
X-UID: 163
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.