Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'default.': 0.09; 'false,': 0.09; 'implements': 0.09; 'operand': 0.09; 'things,': 0.09; 'defer': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'it;': 0.16; 'unequal,': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'normally': 0.19; 'result.': 0.19; 'not,': 0.20; 'seems': 0.21; 'aug': 0.22; 'integer': 0.24; "shouldn't": 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; '3.2': 0.31; '>>>>': 0.31; "we're": 0.32; "can't": 0.35; 'knows': 0.35; 'equal': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'object,': 0.36; 'returning': 0.36; 'done': 0.36; 'behind': 0.37; 'handle': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'back': 0.62; 'skip:n 10': 0.64; 'more': 0.64; 'side': 0.67; 'determine': 0.67; 'reasoning': 0.91; 'directly.': 0.95; '2013': 0.98 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=cO/WUprT6ycsPVQTalizC7GtsCvQwuS3gb+vPXixE9M=; b=jHrhrD21jVPaYPvyPbJkVEUa+LUh3am13LbF/DMqheWR3B91ugi4HfFuW+aF3nfH9H URIJSRHKrB/v234oT91D07gHop4GgwhKZUg03rNTExBn9lo3FZUVw4shoNQ4pVJWsA8T L1iEro4nZA+VDqS50NdAm7Y5ySTTv2aM9hQXozn/mpYcmf1A7yRk1wbOHygtSgKAO7/R tqelVa2fRj5I+cYSKw1p66kU3HRiLDG2EWwdI+0W9bOf3NXP3e76uAXxh2CkNt4nVDHd egwT8Eop7jwOhM0qumWrBthbxdVEdSeRbRZAB33iD82OL7v2icfx+iewARLAUcTtIH1U QaQA== MIME-Version: 1.0 X-Received: by 10.52.89.170 with SMTP id bp10mr4226722vdb.104.1375657576290; Sun, 04 Aug 2013 16:06:16 -0700 (PDT) In-Reply-To: <51FED74E.6080003@markusrother.de> References: <51FED74E.6080003@markusrother.de> Date: Mon, 5 Aug 2013 00:06:16 +0100 Subject: Re: Bug? ( () == [] ) != ( ().__eq__([]) ) 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.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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375658082 news.xs4all.nl 15963 [2001:888:2000:d::a6]:53447 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51943 On Sun, Aug 4, 2013 at 11:35 PM, Markus Rother wrote: > Hello, > > The following behaviour seen in 3.2 seems very strange to me: > > As expected: >>>> () == [] > False > > However: >>>> ().__eq__([]) > NotImplemented >>>> [].__eq__(()) > NotImplemented You don't normally want to be calling dunder methods directly. The reasoning behind this behaviour goes back to a few things, including a way to handle "1 == Foo()" where Foo is a custom type that implements __eq__; obviously the integer 1 won't know whether it's equal to a Foo instance or not, so it has to defer to the second operand to get a result. This deferral is done by returning NotImplemented, which is an object, and so is true by default. I don't see any particular reason for it to be false, as you shouldn't normally be using it; it's more like a "null" state, it means "I don't know if we're equal or not". If neither side knows whether they're equal, then they're presumed to be unequal, but you can't determine that from a single call to __eq__. ChrisA