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

Serhiy Storchaka storchaka at gmail.com
Sat May 5 09:09:39 EDT 2018


05.05.18 15:54, Eloi Gaudry пише:
> I meant avoiding the overhead of the expression evaluation enclosed in the assert itself, not the active/disabled state (that comes at virtually no cost).
> ex:
>>>> runtime_assert( { i:None for i in range( 10000000 ) } )
> 
> By using the syntax you describe ('boolean and not expr'), you loose all the benefit of the Python grammar:
> - self-contained

Could you please explain what you mean?

> - able to catch semantic/syntax bugs
> 
> ex:
>>>> f=1
>>>> runtime_assert( f==1 )
>>>> runtime_assert( f=1 )
>    File "<stdin>", line 1
>      runtime_assert( f=1 )
>                       ^
> SyntaxError: invalid syntax

Until inline assignment expression is implemented, this is an error too:

 >>> if debug and not f=1:
   File "<stdin>", line 1
     if debug and not f=1:
                       ^
SyntaxError: invalid syntax



More information about the Python-ideas mailing list