Skip to content

Do not use assert in validators #26

Open
@jace

Description

@jace

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions