In some places assert statements are being used to perform some kind of validation, e.g.: type of an argument, value of an argument, etc.
These statements should be replaced with proper validation mechanisms that will raise an appropriate Exception and do whatever is necessary from the point of view of the protocol, because such assert statements may be removed if optimization is turned on. From the Python docs:
The current code generator emits no code for an assert statement when optimization is requested at compile time.
Resources
In some places
assertstatements are being used to perform some kind of validation, e.g.: type of an argument, value of an argument, etc.These statements should be replaced with proper validation mechanisms that will raise an appropriate
Exceptionand do whatever is necessary from the point of view of the protocol, because suchassertstatements may be removed if optimization is turned on. From the Python docs:Resources
https://wiki.python.org/moin/UsingAssertionsEffectively:
https://dbader.org/blog/python-assert-tutorial:
https://stackoverflow.com/questions/5142418/what-is-the-use-of-assert-in-python