I love assert

Lie Ryan lie.1296 at gmail.com
Thu Nov 13 09:09:08 EST 2014


On 13/11/14 10:05, Ian Kelly wrote:
> On Wed, Nov 12, 2014 at 3:47 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Ian Kelly <ian.g.kelly at gmail.com>:
>>
>> Apart from idiomatic style, there is no difference between
>>
>>      # never reached
>>
>>      assert False
>>
>>      raise RuntimeError('Unreachable code reached')
>
> If the purpose is communication, then the comment is most effective,
> as it can easily convey anything you want. If the purpose is to detect
> programming errors, then the RuntimeError is most effective, as it
> will always raise an error in the event it is reached.
>
> assert False is a strange hybrid of the two that is less effective at
> both purposes.
>

You can do;

     assert False, "Some comments about why this assert is here"






More information about the Python-list mailing list