-
Notifications
You must be signed in to change notification settings - Fork 87
Running Python with optimizations enabled strips assertions #4
Description
Just wanted to point out that if Python is run with -O (optimize) option, it will strip all assert statements and these checks will effectively disappear:
Line 156 in 033ee08
| assert len(salt) == ARGON2_SALT_LENGTH |
You can read about it more in Python docs.
TL;DR:
Assertions should not be used to test for failure cases that can occur because of bad user input or operating system/environment failures, such as a file not being found. Instead, you should raise an exception, or print an error message, or whatever is appropriate. One important reason why assertions should only be used for self-tests of the program is that assertions can be disabled at compile time.
If Python is started with the -O option, then assertions will be stripped out and not evaluated.
It might still be okay, depending on what the intent is, just wanted to make sure you're aware of this nuance.
PS: Thanks for posting about your work in ModernCrypto mailing list 👍