I love assert

Chris Angelico rosuav at gmail.com
Thu Nov 13 00:10:42 CET 2014


On Thu, Nov 13, 2014 at 10:02 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Wed, Nov 12, 2014 at 3:48 PM, Anton <anschatten at gmail.com> wrote:
>> On Wednesday, November 12, 2014 2:42:19 PM UTC-8, Ian wrote:
>>> On Wed, Nov 12, 2014 at 3:13 PM, Anton <an... at gmail.com> wrote:
>>> > If the code is run optimized and asserts are ignore CONFUSED statement would still not be handled and you will not know about it.
>>> > I would do something like:
>>>
>>> There's no way to make the CONFUSED status be handled without actually
>>> changing the code. The difference is that this version will not
>>> incorrectly treat CONFUSED as WARNING; it just won't do anything at
>>> all if the code is optimized.
>>
>> Right, but the goal is not to make the CONFUSED status be handled without coding, but to be notified about an unknown status code and act accordingly.
>
> Sure, which is why you and I have both suggested raising a RuntimeError instead.

Or, in as many cases as possible, raise an implicit KeyError and save
yourself a lot of typing. Any time these kinds of elif trees can be
turned into dict lookups, you get non-assert error checking for free.

ChrisA



More information about the Python-list mailing list