Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use assert in validators #26

Open
jace opened this issue Aug 9, 2017 · 0 comments
Open

Do not use assert in validators #26

jace opened this issue Aug 9, 2017 · 0 comments

Comments

@jace
Copy link
Member

jace commented Aug 9, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant