[Types-sig] type-assert operator optimizations

skaller skaller@maxtal.com.au
Thu, 23 Dec 1999 08:13:59 +1100


Greg Stein wrote:

> The type-assert operator is *defined* to raise an exception if the type is
> wrong. Period.

	That is not my defintion. And yours has not made
it into the Guido distribution yet, so I am free to make
my own definition :-)
 
> > I'm assuming
> >
> >       1) there is ONE python language
> >       2) both the optimising and non-optimising
> >               byteocode compiler conform to the semantics
> >

> Your two assumptions are correct. 

	I am glad you agree. Consider:

	assert 0

Run that through CPython. It raises an exception, right?
Now run it again, this time with optimisation enabled.
Nothing happens. No exception. The assert statement
was elided by turning on optimisation.
But both compilers are conforming by agreement,
so it follows that an assert statement does NOT
have to raise an exception.

What is required then? Well, it isn't defined!
The program is invalid: it isn't a valid python
program. A third compiler could reject it as such.

[Of course, you COULD specify that either

	a) an exception is raised OR
	b) nothing happens

so that anything else -- like deleting your
hard disk, or rejecting the program -- is not
allowed. In other words, you could make
the behaviour non-determinate, without
making it undefined altogether.]

-- 
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