[Types-sig] Typesafe

Paul Prescod paul@prescod.net
Tue, 04 Jan 2000 17:09:22 -0500


John Ehresman wrote:
> 
> What is the definition of typesafe and what is the definition of isa (or
> "!" or whatever)?  I ask because I thought typesafe meant no code in the
> function could raise a type-related exception (TypeError or
> AttributeError), 

I think that there is a different in kind between an error raised by an
explicit check and one that is likely to be just an accident. Languages
like Java and C++ actually disallow the latter. So I would raise
TypeAssertionError which is unrelated (in terms of the hierarchy) from
TypeError.

> Also, at least one version of the RFC defined the type assertion operator
> as raising a subtype of AssertionError if the type of the value is
> incorrect; does this imply that the exception will only be raised in debug
> mode, like the AssertionError is?  I think you would want it to apply in
> non-debug mode also so that optimized code can safely generated.

Worth debating. Is code that fails an assertion "safe"? I claim no. It
is in error but you just told the compiler that for optimization reasons
you don't care. The same would go for type errors.

 Paul Prescod