[Python-ideas] Runtime assertion with no overhead when not active
barry at barrys-emacs.org
Thu May 10 03:55:44 EDT 2018
> On 7 May 2018, at 18:52, Guido van Rossum <guido at python.org> wrote:
> On Mon, May 7, 2018 at 6:24 AM, Serhiy Storchaka <storchaka at gmail.com <mailto: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
> expands to
> if <controlling flag> and (<expr>):
> raise AssertionError
> In Lisp this would be easy. :-)
This idea requires the same sort of machinery in python that I was hoping for to implement the short circuit logging.
My logging example would be
log( control_flag, msg_expr )
log_function( <msg_expr> )
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas