[Types-sig] type-asserts and check/run -time

Greg Stein gstein@lyra.org
Wed, 5 Jan 2000 15:14:44 -0800 (PST)


Dang. Forgot to fill in my footnote...

On Wed, 5 Jan 2000, Greg Stein wrote:
>...
> The type-assert operator is defined to *always* operate at runtime[*]. The
> user should depend upon this.

[*] This is not entirely true:

1) If the Python compiler is run with the -O switch, then the bytecodes
   for the type-assert are NOT generated. This is analogous to the
   behavior for the "assert" statement today.

2) If the Python runtime is run with the -O switch, then any bytecodes
   generated for an assert will not be executed. Again: analogous to the
   current "assert" statement today.


Background:

Given:

  assert expression, message

Python generates:

  if __debug__ and not expression:
    raise AssertionError, message

The above code is not generated when -O is present. __debug__ is false
when -O is present.

-------------------------------

This is a small part of the definition of the type-assert operator's
behavior at bytecode-generation and at run-time. It does not affect its
behavior at type-check-time.

Cheers,
-g

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