Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'error:': 0.07; 'wednesday,': 0.07; 'indicates': 0.09; 'ignore': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'header:In-Reply-To:1': 0.27; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'assert': 0.31; 'handled': 0.32; 'run': 0.32; 'actual': 0.34; 'something': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'false': 0.36; 'changing': 0.37; 'e.g.': 0.38; 'nov': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'anything': 0.39; '12,': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'remove': 0.60; 'ian': 0.60; 'optimized': 0.68; 'optimized.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=9TJp4c5KYljk9WjpqcivSeYNEwu3pN0/A5Tx71maauM=; b=vgb4Dz6H24WDv75zfta/3WhnE3Irlm3eWh4UbOjhGu2ejqxzxtTOeYRa3iNgxirg9O dVWNQ6YlVfGRv3sw2xPF4UcyDvCdf0zoVmpnQx2kLzBZLeeuu3LB+cmmXt/ucB4rc8TR i5egVSRkjpAhNSDY8KRIjKPLt8o1NJVtGoef0xX6sGQaNyBsGizVWp2CauATkaA7xSbH 4rGqTfZ9QZvt21tAnjeNyYYsIFekDjgc6/b5TPI0RGxH5rnMukBzCwfqLs4ygP72h4mC KxrGsP2Gb/zGppJ8PU50GgCtqtxhfJDHmxMxO2lf8i8WqDlcceEap+Tt2fYue46mW5M4 1IGg== X-Received: by 10.66.252.193 with SMTP id zu1mr4999130pac.153.1415832123046; Wed, 12 Nov 2014 14:42:03 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <0cdc67f4-d9d5-4a73-91fe-7558161246af@googlegroups.com> References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> <87y4rgozgd.fsf@elektro.pacujo.net> <0cdc67f4-d9d5-4a73-91fe-7558161246af@googlegroups.com> From: Ian Kelly Date: Wed, 12 Nov 2014 15:41:22 -0700 Subject: Re: I love assert To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415832125 news.xs4all.nl 2879 [2001:888:2000:d::a6]:39322 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80646 On Wed, Nov 12, 2014 at 3:13 PM, Anton wrote: > On Wednesday, November 12, 2014 2:05:17 PM UTC-8, Ian wrote: >> You don't need to remove it. Just reorganize it to make sure it >> indicates actual exhaustion of possibilities. E.g. using the "assert >> False" pattern from your post: >> >> if status == OK: >> ... >> elif status == ERROR: >> ... >> elif status == WARNING: >> ... >> else: >> assert False > > 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.