flask-lastuser icon indicating copy to clipboard operation
flask-lastuser copied to clipboard

Do not use assert in validators

Open jace opened this issue 7 years ago • 0 comments

As per Python's documentation for the assert statement, an assert expression is equivalent to:

if __debug__:
    if not expression: raise AssertionError

Also:

In the current implementation, the built-in variable __debug__ is True under normal circumstances, False when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time.

This makes using assert for validators unreliable. Flask-Lastuser uses them in a few places. These should be replaced with an explicit if not expression: raise ValueError

jace avatar Aug 09 '17 19:08 jace