Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'test,': 0.05; 'false.': 0.07; 'interpreted': 0.07; 'cc:addr:python-list': 0.09; 'sane': 0.09; 'thread': 0.10; 'language,': 0.11; 'wed,': 0.15; 'blame': 0.16; 'chained': 0.16; 'container,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'parentheses': 0.16; 'rhs': 0.16; 'weird.': 0.16; 'wrote:': 0.16; 'obviously': 0.16; 'language': 0.19; 'people,': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'sep': 0.22; 'bit': 0.23; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'testing': 0.25; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'container': 0.29; 'equality': 0.29; 'raise': 0.29; 'probably': 0.31; "can't": 0.32; 'language.': 0.32; 'getting': 0.33; 'received:google.com': 0.35; 'mix': 0.35; 'but': 0.36; 'should': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'wrong': 0.38; 'mean': 0.38; 'care': 0.60; 'your': 0.60; 'more': 0.63; 'great': 0.63; 'natural': 0.67; 'chrisa': 0.84; 'to:none': 0.91; 'subject:True': 0.93; 'imagine': 0.96 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=4HFqYg5yHma8yzcY5aqk4LE+Kjs2aYX8D1iTU1gm/E8=; b=PTda1qOTS3vdJgHR/Gi6lHZl/sEI8K1bLuasiDAXranD3NTDWLnwdcdMYrjQXfH+2C GDHhSwZC5nfXLz5b7C9ULsuDpYaOCoyTvlpFlJuXdPM8EUOeTZdD5FCKHmU8M4A8Wu+p +OofzOXLdLkARhyy5azEHE+nYPnfSXfJS7UJvjCU1Bu+vn/BRHNZoLwD8tAGuYpPO6OY 6ORSgMsx9hn5X+ZnTcV7Lq4iaLDSlHS7Xo7QY9cxHYigZ9tFu6q+F1wdNhBvftSh0s2q lisYOsyaXq3rprBFZMA9ZQt8UgUdH9immDjLbr75QwbFiGaYqLElNF9KhDRzFdeNFMRG rW5Q== MIME-Version: 1.0 X-Received: by 10.50.50.198 with SMTP id e6mr15704622igo.13.1442408703176; Wed, 16 Sep 2015 06:05:03 -0700 (PDT) In-Reply-To: References: <0b949fe0-09b4-46b0-b4ac-a85a9bfebfd5@googlegroups.com> Date: Wed, 16 Sep 2015 23:05:03 +1000 Subject: Re: True == 1 weirdness From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442408707 news.xs4all.nl 23814 [2001:888:2000:d::a6]:56269 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96674 On Wed, Sep 16, 2015 at 10:53 PM, Jussi Piitulainen wrote: > Ouch. I love chained comparisons more than most people, but this took a > while to decipher. I blame you! Your parentheses mis-primed me for the > wrong reading :) But now I expect to see a long thread about whether > chained comparisons are a natural thing to have in the language. > > The second test, test2, is interpreted (almost) as > > >>>> (1 in {1:1}) and ({1:1} == 1) > > which is obviously False. My view is that they should remain in the language, but that dissimilar comparisons should raise linter warnings. I can't imagine a sane reason for chaining 'in' and equality like that (since the RHS of 'in' will be a container, and if you're testing the whole container for equality, you probably don't care about one member in it), but for language consistency, it's good to support it. Chained comparisons of the same type are a great feature: if 1 < x < 4: And "same type" doesn't just mean the exact same operator: if 1 < x <= 4: It's only when you mix them up in bizarre ways that it's getting a bit weird. ChrisA