sfepy/sfepy — Issue #62: use of assert
Author: rc
Created: 2012-01-30 10:25:11+00:00
State: open

As discussed in [1], using the 'assert' statement as a run-time check in a
production code is problematic, as asserts are removed by -OO option of python.

In SfePy, I propose to do the following:
1. asserts that are used for debugging can stay (it's their purpose)
2. asserts validating user input, sanity checks, bound checks should be
active even in the optimized code (-OO), and thus should be replaced by a
function (let's say assert_).

What do you think?

[1] http://www.mail-archive.com/numpy-discussion@scipy.org/msg12914.html

Migrated from http://code.google.com/p/sfepy/issues/detail?id=58

earlier comments

ondrej.certik said, at 2008-10-01T11:25:34.000Z:

Well, I think that discussion is mainly about tests, no?

robert.cimrman said, at 2008-10-01T11:39:16.000Z:

Yes, the discussion is about tests. But even the tests should work with -OO. And we
use asserts also outside tests to check values, e.g. in meshio.py. Those checks
should not be removed by any option.

ondrej.certik said, at 2008-10-01T11:54:20.000Z:

> But even the tests should work with -OO.

I don't think so. nosetests and py.test use assert to do the tests. So it is a
defacto standard.

robert.cimrman said, at 2008-10-01T12:23:03.000Z:

Actually, in files in tests/ directory is only a minority of asserts, so they can
stay until it causes problems.

robert.cimrman said, at 2008-10-02T11:56:41.000Z:

I was in a mood of doing mindless repetitive tasks, so I introduced assert_().