On Apr 28, 2011, at 04:34 AM, Terry Reedy wrote:
On 4/28/2011 3:54 AM, Tarek Ziadé wrote:
I removed some assert calls in distutils some time ago because the package was not behaving correctly when people were using Python with the --optimize flag. In other words, assert became a full part of the code logic and removing them via -O was changing the behavior.
In my opinion assert should be avoided completely anywhere else than in the tests. If this is a wrong statement, please let me know why :)
My understanding is that assert can be used in production code but only to catch logic errors by testing supposed invariants or postconditions. It should not be used to test usage errors, including preconditions. In other words, assert presence or absence should not affect behavior unless the code has a bug.
I would agree. Use asserts for "this can't possibly happen <wink>" conditions.