Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Rewrite 'assert' statements as if/raise #7831

Closed
3 tasks done
adamchainz opened this issue Mar 11, 2021 · 1 comment
Closed
3 tasks done

Rewrite 'assert' statements as if/raise #7831

adamchainz opened this issue Mar 11, 2021 · 1 comment

Comments

@adamchainz
Copy link
Contributor

Checklist

Python's -O flag, enables "optimized mode" which, among other things, disables the assert statement. A naive user may activate it to try speed up their application. DRF has many uses of assert in its library code (not tests) to guard against bad conditions. Rewriting those assert statements as an if check and a raise of an appropriate exception would allow it to continue functioning in "optimized mode".

@tomchristie
Copy link
Member

I'd probably prefer not. If a user is turning off assertions, then, well, let 'em turn off assertions.

But how about this, shall we get this discussion to a more concrete point first, by taking a single specific example of one of the assert statements in question, to help figure out what the benefits/trade-offs would look like in a particular concrete case?

@encode encode locked and limited conversation to collaborators Mar 11, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants