[Python-ideas] Runtime assertion with no overhead when not active

Guido van Rossum guido at python.org
Mon May 7 13:52:09 EDT 2018


On Mon, May 7, 2018 at 6:24 AM, Serhiy Storchaka <storchaka at gmail.com>
wrote:

> I just don't understand why you need a new keyword for writing runtime
> checks.
>

Oh, that's pretty clear. The OP wants to be able to turn these checks off
with some flag he can set/clear at runtime, and when it's off he doesn't
want to incur the overhead of evaluating the check. The assert statement
has the latter property, but you have to use -O to turn it off. He
basically wants a macro so that

  runtime_assert(<expr>)

expands to

  if <controlling flag> and (<expr>):
      raise AssertionError

In Lisp this would be easy. :-)

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180507/78249273/attachment.html>


More information about the Python-ideas mailing list