[Compiler-sig] Type checking
Charles E Jenkins
cjenkins@tec-usa.com
Mon, 08 May 2000 10:22:05 -0400
Hello to all. I hope this is the correct forum for asking about the whys and
wherefores of Python compilation.
I, too, am interested in seeing strong type-checking added to the language. I
wonder what technical reasons prevent strong runtime type-checking from being
added.
Here's how naive I am. I would think it would be as easy as
def myFunc1( num is IntType )
def myFunc2( any_list is ListType )
def myFunc3( string_list is ListType of StringType )
To have superior type-checking, you'd need some way to define type-safe
constants:
tconst AccessMode is IntType
NONE = 0
GUEST = 1
USER = 2
ADMIN = 3
def setMode( mode is AccessMode ):
if mode != AccessMode.NONE:
blah blah blah
In the example above, calling setMode( 1 ) would result in an exception; you'd
be forced to use setMode( AccessMode.NONE )
And, of course, functions can still accept an argument of any type if the 'is'
clause is omitted.
I call myself naive because this is so easy that there must be a very good
reason why Python doesn't have these facilities!
-- _________________
-- Charles E Jenkins -- MailTo:cjenkins@tec-usa.com