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; 'bug,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; '~ethan~': 0.09; 'def': 0.13; 'boolean': 0.16; 'received:67.18.44': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'subject:function': 0.16; 'warn': 0.16; 'wrote:': 0.18; '(or': 0.22; "doesn't": 0.22; 'header:In- Reply-To:1': 0.22; 'somewhere': 0.23; 'tests.': 0.23; 'noticed': 0.24; 'cc:2**0': 0.24; "i'm": 0.26; 'function': 0.27; 'cc:addr:gmail.com': 0.28; 'true,': 0.29; 'times.': 0.30; "i've": 0.31; 'quite': 0.32; 'header:User-Agent:1': 0.33; 'instead': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'something': 0.35; 'problem.': 0.36; 'think': 0.37; 'could': 0.37; 'some': 0.38; 'couple': 0.38; 'subject:from': 0.38; 'else': 0.39; 'tool': 0.39; 'why': 0.39; 'to:addr:python.org': 0.40; 'received:websitewelcome.com': 0.64; 'ever': 0.65; 'believe': 0.65; 'received:184': 0.67; 'andrea': 0.84; 'bitten': 0.84; 'that)': 0.84; 'received:gateway04.websitewelcome.com': 0.91; 'stupid': 0.91 Date: Tue, 13 Dec 2011 09:42:05 -0800 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: python-list@python.org Subject: Re: boolean from a function References: <4EE77C25.1060600@gmail.com> In-Reply-To: <4EE77C25.1060600@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:4711 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 4 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323801308 news.xs4all.nl 6884 [2001:888:2000:d::a6]:42247 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17160 Andrea Crotti wrote: > I'm not sure for how long I had this bug, and I could not understand the > problem. > > I had a function which would return a boolean > > def func_bool(): > if x: > return True > else: return False > > Now somewhere else I had > > if func_bool: > # do something > > I could not quite understand why it was always true, until I finally > noticed that the () were missing. > Is there some tool to avoid these stupid mistakes? (pylint doesn't warn > me on that) > I don't think I will ever (or almost) have to use a function as a > boolean, instead of its return value... Heh, I do believe I've been bitten by that a couple times. The only defense I'm aware of is good unit tests. ~Ethan~