Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'error:': 0.07; 'modified': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'wrote:': 0.18; 'do.': 0.18; 'example': 0.22; 'header:User-Agent:1': 0.23; 'header :In-Reply-To:1': 0.27; 'code': 0.31; 'assert': 0.31; 'run': 0.32; 'there,': 0.34; 'should': 0.36; 'being': 0.38; 'handle': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'new': 0.61; 'received:173': 0.61; 'optimized': 0.68; 'warning.': 0.84; 'imagine': 0.93 Date: Wed, 12 Nov 2014 13:52:48 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: I love assert References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> In-Reply-To: <87a93wqeq3.fsf@elektro.pacujo.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415829173 news.xs4all.nl 2906 [2001:888:2000:d::a6]:59462 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80635 On 11/12/2014 01:41 PM, Marko Rauhamaa wrote: > > Or I might indicate the exhaustion of possibilities: > > if status == OK: > ... > elif status == ERROR: > ... > else: > assert status == WARNING > ... And here's a nice example of what one should NOT do. Imagine that a new status, CONFUSED is added, the above code is not modified to handle it, and for whatever reason the program is being run optimized -- the assert is not there, and CONFUSED is treated the same as WARNING. -- ~Ethan~