Read the manual:
http://docs.python.org/reference/simple_stmts.html#the-assert-statement
"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."
HTH,
~Simon
You should be very careful not to put unit tests in asserts because that
prevents you from testing your application under optimization.
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
The best way to get information on Usenet is not to ask a question, but
to post the wrong information.
Anyway that does not answer your question I'm sorry to be off topic,
'tis just a thought. Simon gave you the proper answer.
Jean-Michel
Actually, if an assert statement is never raised in production code
irrespective of the condition (even in case of malicious inputs), it is
the correct use of assert statement. The difficulty is in proving that
it is impossible to raise the assert. In most cases it is impossible to
prove and we just turn off assert when we're quite confident that it is
bug-free enough.
Why not? "Would never" is a very common English phrase, and
the OP used it correctly.
Not the same concern. Assertions are here for 1/ documention of expected
state / value / pre|post conditions etc, and 2/ automatic verification
of these expectations *during development* - so you can immediatly spot
and fix failed expectations. IOW, it's about the "this should not, no
way, never possibly happen" cases, not the "this may eventually happen"
ones - which indeed require "proper" handling at the level you expect them.
I can see this issue has several facets to it, so I don't intend to
flagratly contradict your experience Jean-Michel, but I think that in
at least some circumstances asserts used in this way can be valuable.
One of the interesting points to come out of the recent flurry of
empirical studies of software engineering is that quality of code as
measured by defect density shows a definite negative correllation with
use of asserts in production code. (Although the significance of this
is somewhat lessened by the fact that both use of asserts and low
defect density are correlated with the level of developer experience.)
Original Microsoft paper here:
http://research.microsoft.com/apps/pubs/default.aspx?id=70290
Summary article discussing that paper and others:
http://research.microsoft.com/en-us/news/features/nagappan-100609.aspx
Personally, I'm curious as to whether the benefit from asserts used in
this way is in helping the developer to clarify in their own mind
exactly what their expectations and invariants are.