On Jul 3, 2009, at 2:03 PM, Steven D'Aprano wrote:

On Fri, 03 Jul 2009 16:19:22 +0000, kj wrote:

In <[email protected]> Alan G Isaac
<[email protected]> writes:

1. Don't use assertions to test argument values!

Out of curiosity, where does this come from?

Assertions are disabled when you run Python with the -O (optimise) flag.
If you rely on assertions to verify data, then any time the user runs
python with -O your code will be running without error checking.

assert should be used to verify program logic, not to sanitize data.


I wouldn't describe the use of an assert statement in the original code as data sanitizing, but rather as a precondition. And with that description, the use of an assert statement that might be compiled away is not unreasonable; indeed, it certainly is so in the context of design by contract.

Charles Yeomans
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to