Assertions

Steve D'Aprano steve+python at pearwood.info
Fri Sep 22 07:15:54 EDT 2017


On Fri, 22 Sep 2017 08:50 pm, alister wrote:

>> The bottom line is, if I saw
>> 
>> if not (thing > 0): raise AssertionError(...)
>> 
>> in a code review, I'd probably insist that either it be changed to use
>> `assert`,
>> or the exception be changed to ValueError, whichever better expresses
>> the intention of the code.
> 
> In a code review I would want the condition changed to be less noisy/
> confusing to the reader.
> 
> if thing <=0: whatever

Fair point, assuming they are the same.

Actually, even for floats they're not the same.

py> not (NAN > 0)
True
py> NAN <= 0
False


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list