Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.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.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'elif': 0.05; 'wednesday,': 0.07; 'coding,': 0.09; 'sure,': 0.09; 'trees': 0.09; 'cc:addr :python-list': 0.11; 'dict': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'keyerror': 0.16; 'accordingly.': 0.16; 'ignore': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'possible,': 0.19; 'thu,': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'instead.': 0.24; 'cc:2**0': 0.24; 'suggested': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; '13,': 0.31; 'implicit': 0.31; 'handled': 0.32; 'run': 0.32; 'cases': 0.33; 'checking': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'raising': 0.36; 'changing': 0.37; 'nov': 0.38; 'pm,': 0.38; 'anything': 0.39; '12,': 0.39; 'ian': 0.60; 'save': 0.62; 'act': 0.63; 'notified': 0.63; 'optimized': 0.68; 'goal': 0.75; 'yourself': 0.78; 'optimized.': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=GZZgYsYI7C32uj9SzPjC6IJ8Y9HQ1NAok1llc6BaLwE=; b=akQtvte0joMgg5PNoinJ06pTZ+RFXnG5tfCFk27ZBGKR+uGzRJBrLXe+KwZqmOqouT T+Sm95Ab5g722MBBn3yZ3JskDZMPtLzagvF/1EpjW+Ewr9Ov4DJ/t5FHs/kGODAE1o2R FTTvvqf8qQVrd467/ujvLwNzjg7WrP9wrUoQkIPeCNOgPRKfaSgBDno3e30vnzdAIfF8 O9XiGfFRP9vr1N8pNuMMDJ/XayqfS08Ty/WU6i2i1U2o6xAxSeszP266LkT0sB7yVH/o 66tPxuknwga43ZRzGHyKjHMWS1wKGHOqZvCJJCLrBd3E2sxfVp0pto0PYd7eYY1wg0vq v8NQ== MIME-Version: 1.0 X-Received: by 10.50.110.4 with SMTP id hw4mr43373596igb.14.1415833842211; Wed, 12 Nov 2014 15:10:42 -0800 (PST) In-Reply-To: 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> <28e159ff-3d64-4793-9082-05cf1553c7c2@googlegroups.com> Date: Thu, 13 Nov 2014 10:10:42 +1100 Subject: Re: I love assert From: Chris Angelico Cc: 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: 1415833844 news.xs4all.nl 2859 [2001:888:2000:d::a6]:41565 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80656 On Thu, Nov 13, 2014 at 10:02 AM, Ian Kelly wrote: > On Wed, Nov 12, 2014 at 3:48 PM, Anton wrote: >> On Wednesday, November 12, 2014 2:42:19 PM UTC-8, Ian wrote: >>> On Wed, Nov 12, 2014 at 3:13 PM, Anton 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