Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'error:': 0.07; 'expectation': 0.09; 'indicates': 0.09; 'executed,': 0.16; 'then?': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'assert': 0.31; 'actual': 0.34; "i'd": 0.34; 'something': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'e.g.': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; '12,': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'remove': 0.60; 'ian': 0.60; 'honest': 0.78 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=D4FUVdOpG16HHoZn2D8GDFLfxenOHu+cvYEHUVjE0lE=; b=UgchZhfAM/nSTfAukMvCeWOIe0gTpBv2mes+KBZdecAxTBQ4Fcvmnb5ikWITTm8+Fl mSyzDG3SsrPAYSPwX+BFoUVqMmlV8A3oRoS6Do5yd3669FjuUWzYwE7iEAnrN1jm6zsi F/1W+C0L5oidNmgXHBhfH9P9RTHCQ8WlbOkizHSs8PyoKODTYW35oB47XQVBsxYvvGJk 3D7qpwP08G0NZY4W2kL+gESNxfPeRpHBCohWNynJF9f13U07Ojz2T9t6/jeMtldXrvlL r+ZJlJU8/JKPLqa7UUs9kWy6F+d3PWTJn2O0L+x0BR7igfqdvzsDNZqYeHXwEpC35Hqa nwsA== X-Received: by 10.70.47.195 with SMTP id f3mr20297196pdn.156.1415830079497; Wed, 12 Nov 2014 14:07:59 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> <87y4rgozgd.fsf@elektro.pacujo.net> From: Ian Kelly Date: Wed, 12 Nov 2014 15:07:19 -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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415830087 news.xs4all.nl 2900 [2001:888:2000:d::a6]:50545 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80641 On Wed, Nov 12, 2014 at 3:04 PM, Ian Kelly wrote: > On Wed, Nov 12, 2014 at 2:56 PM, Marko Rauhamaa wrote: >> How would it be better if you removed the assert then? > > 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 Although to be honest I'd rather use something like "raise RuntimeError('Unreachable code reached')" than "assert False" here. If the expectation is that the code will never be executed, then there's no reason to ever optimize it out.