Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!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; 'none:': 0.07; 'convention,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'recommends': 0.09; 'python': 0.11; '"is"': 0.16; 'finney': 0.16; 'none.': 0.16; 'pathological': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'singleton': 0.16; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'comparing': 0.24; 'people,': 0.24; 'compare': 0.26; 'right.': 0.26; 'header:X-Complaints-To:1': 0.27; 'correct': 0.29; 'compared': 0.30; 'returned': 0.30; "i'm": 0.30; 'code': 0.31; 'lines': 0.31; 'equality': 0.31; 'writes:': 0.31; 'yes.': 0.31; 'cases': 0.33; 'except': 0.35; 'case,': 0.35; 'there': 0.35; 'version': 0.36; 'received:com.au': 0.36; 'two': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'even': 0.60; 'tell': 0.60; 'such': 0.63; 'more': 0.64; 'different': 0.65; 'protect': 0.79; 'received:125': 0.84; 'widespread': 0.91; 'convinced': 0.93; 'hill': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Reference Date: Tue, 04 Mar 2014 09:17:55 +1100 References: <53144e8d$0$2149$426a74cc@news.free.fr> <1d1dfa1b-b715-4d8f-9c12-f0d3dc1a22c9@googlegroups.com> <85ppm3httu.fsf@benfinney.id.au> <20140303155112.46e34ff8@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: vmx15867.hosting24.com.au X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:zvxqtfdtv6Gw//wrZfST3NZpegk= 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1393885090 news.xs4all.nl 2837 [2001:888:2000:d::a6]:58071 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67600 Jerry Hill writes: > if foo == None: > do_stuff() > > The only time it would give you a different result from the "is" > version is if foo was bound to an object that returned True when > compared with None. That's right. Python provides this singleton and then recommends you compare with ‘is’, precisely to protect against pathological cases like a “return True when compared for equality with None” data type. Using ‘if foo is None’ means you don't even have to spend time worrying about such cases. > And if that were the case, I'm still not convinced that you can tell > from looking at those two lines of code which one is buggy, except for > the fact that there has been 20 years of custom saying that comparing > to None with equality is wrong. Yes. And because of that widespread convention, it's much more correct to compare against None with ‘is’. -- \ “Always do right. This will gratify some people, and astonish | `\ the rest.” —Mark Twain | _o__) | Ben Finney