[Types-sig] type-assert operator optimizations

Greg Stein gstein@lyra.org
Wed, 22 Dec 1999 13:46:52 -0800 (PST)


On Thu, 23 Dec 1999, skaller wrote:
>...
> 	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.

The assert statement has different meanings based on the compiler you use.
That's all. Nothing funny about that.

In one case, it is defined to test and value and raise an
exception. In the other, it is a no-op.

> What is required then? Well, it isn't defined!

Yes, it is. It is just defined differently for the two compilers.

> The program is invalid: it isn't a valid python
> program.

It is entirely valid.

> A third compiler could reject it as such.

Sure: it could say "this thing will always fail, so I won't compile this
code."

But you're still missing the point. "assert" has a very specific
definition, and that is to raise an exception if its value is zero. It is
also defined to be a no-op in an optimizing compiler.

I do not see where you're going with all this. Exceptions are part of
Python. They exist, and they must be raised when needed. Your attempt to
redefine their role in Python is getting awfully tiresome.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/