Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'detect': 0.07; 'false,': 0.09; 'reached.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '"some': 0.16; 'convey': 0.16; 'here"': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'programming': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'code': 0.31; 'comments': 0.31; 'assert': 0.31; 'comment': 0.34; 'there': 0.35; 'false': 0.36; 'received:com.au': 0.36; 'two': 0.37; 'easily': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'ian': 0.60; 'most': 0.60; 'effective': 0.61; 'reached': 0.63; 'charset:windows-1252': 0.65; 'between': 0.67; 'apart': 0.72; 'received:110': 0.96 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Lie Ryan Subject: Re: I love assert Date: Fri, 14 Nov 2014 01:09:08 +1100 References: <96c138e4-ab95-4e5f-a0c8-e696b5a926bb@googlegroups.com> <87a93wqeq3.fsf@elektro.pacujo.net> <87y4rgozgd.fsf@elektro.pacujo.net> <87lhngox30.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 110-175-240-90.static.tpgi.com.au User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415887762 news.xs4all.nl 2976 [2001:888:2000:d::a6]:52003 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3984 X-Received-Body-CRC: 763643947 Xref: csiph.com comp.lang.python:80686 On 13/11/14 10:05, Ian Kelly wrote: > On Wed, Nov 12, 2014 at 3:47 PM, Marko Rauhamaa wrote: >> Ian Kelly : >> >> 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"