[Types-sig] Run time arg checking implemented

skaller skaller@maxtal.com.au
Fri, 24 Dec 1999 03:48:59 +1100

I have implemented run time argument checking in Viper,
using Greg's ! operator. The syntax (so far) is like:

	def f( p ! t = dflt): pass

and the semantics are to check that an argument
has the nominated type:


checks like:

	if type(a) is not t:
		raise TypeError "messge"

There is no return type declaration or checking,
and the type can be an arbitrary expression.
[In Viper, any object can be a type]
Even if a parameter has a default argument,
it is not checked at the point of definition.
The type is bound at the point of definition.
Implementation time, a few hours.
Tuple parameters are checked componentwise:

	def f((a!t1, b!t2)) : pass

We're not talking any complex type checking,
inference, or anything else here .. but this
could, IMHO, be implemented easily in CPython,
well in time for 1.6. Again, it _looks_ nice to me, 
and it sits well with the expression form

	x ! t

>>>t = type(1)
...def f(x!t): pass

Uncaught Python Exception at top level!!
  .. Kind: Instance of TypeError
  .. Attributes:
      args --> Argument 1 in call to function f has type <class
PyStringType> but type <class PyIntType> is required 

John Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850