python - Does precondition assertion testing replace assumptions in a function specification or vice versa? -
i'm confused when use assertion testing in python functions. if specify assumptions regarding input arguments function, should assume correct input being fed function or should use assertions check conditions on input args enumerated in specification?
if you're writing "public" function, believe pythonic way check arguments (using if
, not assert
), and, if they're invalid, raise exception type , info / message designed provide info possible.
if you're writing function designed internal use, using assert
check arguments seems idea me.
Comments
Post a Comment