Typing arguments in python
Erik Max Francis
max at alcyone.com
Wed Apr 16 19:20:02 EDT 2003
"A. Lloyd Flanagan" wrote:
> An assert is technically a
> statement that a certain condition can't happen under any
> circumstances. It's used to verify that the code in the function has
> the expected effect on the state of the program. But being called
> with an incorrect parameter is NOT a flaw in the code that contains
> the assert -- it's a problem with the caller. Basically, instead of
> saying, "hey, buddy, that parameter is wrong" you're now saying
> "whoops, there's a bug in my code somewhere". For a bad parameter you
> should raise ValueError or something similar, not AssertionError.
Some programming houses break asserts into two types: logic asserts and
data asserts. Logic asserts are the traditional "can't happen; if it
did something is disastrously wrong" variety, but data asserts are the
"you sent me bad data, dummy" form. This way you select differing
behavior (ignore them completely, print a warning message in a log file,
or abort immediately) on each of them separately.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ Would a harvest from my heart / Find its season
\__/ Sandra St. Victor
Python chess module / http://www.alcyone.com/pyos/chess/
A chess game adjudicator in Python.
More information about the Python-list
mailing list