Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion checking for identity before comparing built-in objects

Received: by 10.180.8.233 with SMTP id u9mr2689472wia.3.1349725909096;
        Mon, 08 Oct 2012 12:51:49 -0700 (PDT)
X-BeenThere: python-ideas@googlegroups.com
Received: by 10.180.105.1 with SMTP id gi1ls8249174wib.2.canary; Mon, 08 Oct
 2012 12:51:49 -0700 (PDT)
Received: by 10.180.73.173 with SMTP id m13mr2685001wiv.4.1349725909059;
        Mon, 08 Oct 2012 12:51:49 -0700 (PDT)
Received: by 10.180.73.173 with SMTP id m13mr2685000wiv.4.1349725909050;
        Mon, 08 Oct 2012 12:51:49 -0700 (PDT)
Return-Path: <python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>
Received: from mail.python.org (mail.python.org. [2001:888:2000:d::a6])
        by gmr-mx.google.com with ESMTPS id fb20si1078588wid.3.2012.10.08.12.51.49
        (version=TLSv1/SSLv3 cipher=OTHER);
        Mon, 08 Oct 2012 12:51:49 -0700 (PDT)
Received-SPF: pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 2001:888:2000:d::a6 as permitted sender) client-ip=2001:888:2000:d::a6;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 2001:888:2000:d::a6 as permitted sender) smtp.mail=python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org; dkim=pass header...@python.org
Received: from albatross.python.org (localhost [127.0.0.1])
	by mail.python.org (Postfix) with ESMTP id 3XbBzS5F9YzQv4
	for <python-ideas-garchive-35620@googlegroups.com>; Mon,  8 Oct 2012 21:51:48 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901;
	t=1349725908; bh=aZBdUrZODwpiicnaQGqn1nLmO7JV42ws16rjTXHuVdI=;
	h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:To:Cc:
	 Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:
	 List-Subscribe:Content-Type:Content-Transfer-Encoding:Sender;
	b=k5Ek9h5cOUIylfDfzSy7atkpxgvK4wiJsk4Bn+64T2BTetaHMpruUkfFbMnvPY0n3
	 o8pMvBR0ziZSGX0Lr2AoVt3SxbwfN0DETLoVwzpJtlsQ4koBStgKoNlabXev5hfDEi
	 hJGVpg23ozj4mXU4LkXa7j4g7znWLp6RfGe8DKjU=
X-Original-To: python-id...@python.org
Delivered-To: python-id...@mail.python.org
Received: from albatross.python.org (localhost [127.0.0.1])
	by mail.python.org (Postfix) with ESMTP id 3XbBsz6XdlzQrp
	for <python-id...@python.org>; Mon,  8 Oct 2012 21:47:03 +0200 (CEST)
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03;
	'true,': 0.04; 'subject:Python': 0.05; 'guido': 0.05;
	'sequences.': 0.07; 'true)': 0.07; 'itself,': 0.09; 'rossum':
	0.09; 'shortcut': 0.09; 'anyway': 0.11; 'itself.': 0.11;
	'applies': 0.15; '(true,': 0.16; 'conclusion:': 0.16;
	'containers': 0.16; 'iterating': 0.16; 'oct': 0.16; 'pairs': 0.16;
	'subject:ideas': 0.16; 'unequal': 0.16; 'mon,': 0.16;
	'from:addr:python.org': 0.17; 'wrote:': 0.17; 'comparing': 0.17;
	'exists': 0.17; 'found,': 0.17; 'items.': 0.17; 'pointer': 0.17;
	'>>>': 0.18; 'sender:addr:gmail.com': 0.18; 'subject:] ': 0.19;
	'bug?': 0.22; 'keyboard': 0.22; 'required.': 0.22;
	'received:74.125.82.174': 0.23; 'cc:2**0': 0.23; 'elements': 0.23;
	'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25;
	'common': 0.26; 'first,': 0.27; 'rules': 0.27; 'message-
	id:@mail.gmail.com': 0.27; '>>>>': 0.29; 'behaviour': 0.29;
	'comparison': 0.29; 'container': 0.29; 'van': 0.29; "i'm": 0.29;
	'lists': 0.31; 'received:74.125.82': 0.33; 'equal': 0.33;
	'received:google.com': 0.34; 'compared': 0.35; 'identity': 0.35;
	'pm,': 0.35; 'similar': 0.35; 'there': 0.35; 'really': 0.36;
	'but': 0.36; 'received:74.125': 0.36; '(i.e.': 0.36; 'compare':
	0.36; 'thank': 0.36; 'possible': 0.37; 'itself': 0.37; 'does':
	0.37; 'two': 0.37; 'why': 0.37; 'item': 0.37; 'quite': 0.37;
	'far': 0.37; 'mean': 0.38; 'object': 0.38; 'where': 0.40;
	'subject:-': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'real':
	0.61; 'back': 0.62; 'different': 0.63; 'more': 0.63; 'results':
	0.65; 'soon': 0.70; 'special': 0.73; 'forced': 0.84;
	'subject:before': 0.84; 'to:addr:btinternet.com': 0.84
Received: from localhost (HELO mail.python.org) (127.0.0.1)
	by albatross.python.org with SMTP; 08 Oct 2012 21:47:03 +0200
Received: from mail-we0-f174.google.com (mail-we0-f174.google.com
	[74.125.82.174])
	(using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits))
	(No client certificate requested)
	by mail.python.org (Postfix) with ESMTPS
	for <python-id...@python.org>; Mon,  8 Oct 2012 21:47:03 +0200 (CEST)
Received: by mail-we0-f174.google.com with SMTP id t9so2771752wey.19
	for <python-id...@python.org>; Mon, 08 Oct 2012 12:47:03 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
	h=mime-version:sender:in-reply-to:references:from:date
	:x-google-sender-auth:message-id:subject:to:cc:content-type;
	bh=K0HpKfYMUgAA/V1OEZxLnSlGhPb1fBRX7Ogtm2Y38dU=;
	b=SufIWpoopbYrFBznelr98rtZlSpzL6FpS0fpD4IAVCj1+aql4c+yTU0XFmX4DDChBC
	42x4FQqgahGjqQ77Ic0ml3GoeZTD7H9UCtvIYIziRi6d+l7IGhkDd0lJOn4magRCYDip
	9KfriZoG3qfZCGH0U2Elx2V5ZDbWINXVadykNN47TXSh5DQBF0NKvYF0EOn0Dt9xTiCp
	VQKuaZmeH1qUPocMKN1Qajy32sIAGL4SDONKzIV7uN0GX0/Gm4qokAerkGl9cXKTFoqO
	XN3NUW/DW7W8LTUzxCKFjYt9cOtBHd1rghpzHYjm9DgSE7yX+Q2Jh7xwO0D65KpLd2Rl
	pZpA==
Received: by 10.180.87.230 with SMTP id bb6mr23634057wib.6.1349725623437; Mon,
	08 Oct 2012 12:47:03 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.194.19.131 with HTTP; Mon, 8 Oct 2012 12:46:43 -0700 (PDT)
In-Reply-To: <50732385.2090...@btinternet.com>
References: <CAOVPiMhnBezrw3gusD1QmW8MawV1HDCQHiTbd2Z0_T1TLDa...@mail.gmail.com>
	<506D94EE.30...@pearwood.info>
	<CAP7h-xZBg-MbWtmWFSQ4HmSPjCO_+Av_f-ip6hrH8WBSPJv...@mail.gmail.com>
	<CAPTjJmrRENuYXMOjPzobY1Hjkr+Vmqq04Z4_JOr6=DCdP4-...@mail.gmail.com>
	<CAP7h-xb4WvNuDGayqe60GRGmV4Nk-nzcN1d=HLahHw-hkG7...@mail.gmail.com>
	<CAP7+vJ+G-0WXZRTgr5Y=T+OdaMWmGzgk1--UH8=zoBGLsia...@mail.gmail.com>
	<CAP7h-xaV3RaA2EW4+vWuU=L=2JjhnKBGqhHPhgnmf4VbgGm...@mail.gmail.com>
	<CAP7+vJLt_WNzS75S25kMgPjFMiKz5DFCj5V69ZeyiWsYs5A...@mail.gmail.com>
	<50723BE5.3060...@nedbatchelder.com> <507243D2.8000...@btinternet.com>
	<CAP7+vJ+s+1o05t1WmgBxUEdLLdZX-vXMvZw8bMsDAzSv34i...@mail.gmail.com>
	<507308A6.60...@btinternet.com>
	<CAP7+vJ+EMnC6T+2yDkawjWiY6EKzz846wy+oO=_t8Qax76C...@mail.gmail.com>
	<CAP7+vJKS-eJsGgxDxSagCst9Jsr_SLvYZg+wKgerup1h1WT...@mail.gmail.com>
	<50732385.2090...@btinternet.com>
From: Guido van Rossum <gu...@python.org>
Date: Mon, 8 Oct 2012 12:46:43 -0700
Message-ID: <CAP7+vJ+RUNMjgBah7mvRc5xHqSMa4QrM6SyFgSHZq3qytsP...@mail.gmail.com>
To: Rob Cliffe <rob.cli...@btinternet.com>
Cc: Python-Ideas <python-id...@python.org>
Subject: Re: [Python-ideas] checking for identity before comparing built-in
	objects
X-BeenThere: python-id...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Discussions of speculative Python language ideas
	<python-ideas.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/python-ideas>,
	<mailto:python-ideas-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-ideas/>
List-Post: <mailto:python-id...@python.org>
List-Help: <mailto:python-ideas-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-ideas>,
	<mailto:python-ideas-requ...@python.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org
Sender: "Python-ideas"
	<python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>

On Mon, Oct 8, 2012 at 12:03 PM, Rob Cliffe <rob.cli...@btinternet.com> wrote:
>
> On 08/10/2012 19:39, Guido van Rossum wrote:
>>
>> Does this mean that the following behaviour of lists is a bug?
>>>>>>>
>>>>>>> x=float('NAN')
>>>>>>> [x]==[x], [x]<=[x], [x]>=[x]
>>>>
>>>> (True, True, True)
>>>
>>> No. That's a special case in the comparisons for sequences.
>>
>> [Now that I'm back at a real keyboard I can elaborate...]
>>
>> This applies to all container comparisons: without the rule that if
>> two contained items reference the same object they are to be
>> considered equal without calling their __eq__, containers couldn't
>> take the shortcut that a container is always equal to itself (i.e. c1
>> is c2 => c1 == c2). Without this shortcut, container comparisons would
>> be much more expensive: any time a large container was compared to
>> itself, it would be forced to recursively compare all the contained
>> items. You might say that it has to do this anyway when comparing to a
>> container that is not itself, but if the anser is "unequal" the
>> comparison can stop as soon as two unequal items are found, whereas if
>> the answer is "equal" you end up comparing all items. For two
>> different containers there is no possible shortcut, but comparing a
>> container to itself is quite common and really does deserve the
>> shortcut. We discussed this in the past and always came to the same
>> conclusion: despite the rules for NaN, the shortcut for containers is
>> required. A similar shortcut exists for 'x in [x]' BTW.
>>
> Thank you for elaborating, I was going to ask what the justification for the
> special case was.
> You have explained why
>
>>>> x=float('NAN'); A=[x]; A==A
> True
>
> but not as far as I can see why
>
>>>> x=float('NAN'); A=[x]; B=[x]; A==B, [x]=[x]
> (True, True)
>
> where neither of the results is comparing a container to itself.

It's so that when the container is iterating over pairs of elements it
can check for item identity (a simple pointer comparison) first, which
makes a pretty big difference in speed.

-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas