[Python-ideas] Runtime assertion with no overhead when not active
Serhiy Storchaka
storchaka at gmail.com
Sat May 5 08:05:16 EDT 2018
05.05.18 11:04, Eloi Gaudry пише:
> Briefly, the idea is to add a new assert that can be switch on/off
> depending on some variable/mechanism at runtime. The whole point of
> this assert is that it should not bring any overhead when off, i.e.
> by avoiding evaluating the expression enclosed in the runtime
> assert. It thus relies on Python grammar.
You should have an overhead for checking if it is switched on/off,
isn't? And this overhead is virtually the same as testing the value of
the global boolean variable.
> runtime_assert( expr )
>
> #would result in if expr and runtime_assert_active:
>
> print RuntimeAssertionError()
How this will be different from
if debug and not expr:
print(RuntimeAssertionError())
?
More information about the Python-ideas
mailing list