[rfc] avoid assert statements?
John Arbash Meinel
john at arbash-meinel.com
Mon Oct 1 16:42:45 BST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Martin Pool wrote:
> The question of when it's ok to use 'assert' has come up in a few
> reviews recently; Robert suggested we should set a standard for it. I
> wouldn't say it's hugely urgent but thought I'd write this down rather
> than forget it.
>
> As you probably know, assert is equivalent to
>
> if __debug__:
> if not CONDITION:
> raise AssertionError(MESSAGE)
>
> where __debug__ is controlled by the Python -O flag, which is normally absent.
I tend to think of "assert" as a check for developers, which is meant to
be disabled for most people at runtime.
That way when I'm prototyping something new I'll get an assertion error
if I ask the wrong thing.
I would be happy enough to have the default installer set the '-O' flag.
So that running from source would be normal, but running from an
installed bzr would have assertions removed.
I agree that there are places which are either "this always needs to be
check, so check for real and raise a real error" and there are some
which are "I'm prototyping, so let me check my assumptions" which we
don't need in production code anymore.
I don't really want to see a general "don't use assert" because I think
it is a useful tool.
But then again, maybe it is only really useful for developing/debugging,
and thus shouldn't ever be in bzr.dev....
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFHARV1JdeBCYSNAAMRAvd/AKDZEaP/NE02Ch1xrbEpR/dGLrhfSQCfcwD7
RcL4srHSagVWM4/l76ch+BM=
=dzpl
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list