Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'value,': 0.03; 'false.': 0.07; '"if': 0.09; 'forcing': 0.09; "object's": 0.09; 'subject:while': 0.09; '"if"': 0.16; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'redundant.': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'handles': 0.18; 'received:209.85.214.174': 0.21; 'implicit': 0.22; '15,': 0.23; 'statement': 0.23; 'raise': 0.24; 'thus': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'rules': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.30; 'resolution': 0.30; 'point': 0.31; 'johnson': 0.32; 'values.': 0.33; 'to:addr:python-list': 0.33; 'skip:b 20': 0.34; 'received:google.com': 0.34; 'described': 0.35; 'false': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'anything': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'july': 0.60; "you've": 0.61; 'procedure': 0.61; 'jul': 0.65; 'presented': 0.72; 'construct': 0.84; 'ridiculously': 0.84; 'viable': 0.84; 'rick': 0.91; 'yes!': 0.93 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:to :content-type; bh=g5TbGQk68jvn1wx6O2eC6QJJ8j3tfFMPI9dePiXdFJQ=; b=GD7LrKv39TjoxwUKzeAwwdWWbPfPYk/8sLHllpQx3EdOZpcBaUyfYBe015IWVd3hEA 0PWPQBhBztqIIYvMBGnFbrEy2n4+XGvufdAho6r/WYCoQ1WHiNPg0kr79XQTbf7NbrfQ G+BpqBOkkPVzX60op3ZBpdTaJBtsD5HKMqLruqVtJCdw0IFWLyrVlkayrVmleHVAJORs U+9hEzrmaPdZQ6Y8pvHDtryyXqyISTJbO54Eb2i6pwEfwwOIoD3dkm+RorNtea1Io2+9 +5f7A3bTeywjzpKCu5LUKKpfgEa3SaJNNT6cjPZZcUSaaP2rkRl7xfa47RgT8HUeQ6A6 LFoQ== MIME-Version: 1.0 In-Reply-To: References: <5002a1f9$0$29995$c3e8da3$5496439d@news.astraweb.com> <7b027612-a07e-40f9-8ad2-3e95c5440482@googlegroups.com> Date: Mon, 16 Jul 2012 07:53:09 +1000 Subject: Re: Implicit conversion to boolean in if and while statements From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342389192 news.xs4all.nl 6935 [2001:888:2000:d::a6]:52161 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25374 On Mon, Jul 16, 2012 at 4:56 AM, Rick Johnson wrote: > On Sunday, July 15, 2012 1:01:58 PM UTC-5, Ian wrote: > >> So now instead of having to understand how "if" handles arbitrary >> values, we have to understand how "bool" handles arbitrary values. >> How is that an improvement? > > Because we are keeping the condition consistent. We are not relying on implicit resolution of an object's value based on some dark, esoteric and inconsistent rules that defy all normal logic. > >> What should "if" do if presented a value that isn't True or False? >> Raise a TypeError? > > YES! Because IT IS the author's responsibility to present a condition that evaluates to either True or False. Anything else would be ridiculously inconsistent. Then the construct "if bool(some_condition):" is redundant. What you've described is a viable system (REXX, for instance, demands that an IF statement be given strictly either a 1 or a 0 (there's no True and False values, but you're not allowed to use 527 as a True value, it has to be 1)), but it's still redundant to attempt the cast. For instance, this REXX function will logically negate a value twice, thus forcing it to boolean: bool: procedure return \\arg(1) But if it's given a non-bool, it'll just bomb, exactly the same as the if statement would. So Ian's point still stands. ChrisA