Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Effects of caching frequently used objects, was Re: Explaining names vs variables in Python Date: Sat, 26 Mar 2016 00:22:33 +1100 Lines: 29 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de aY8fsSyni5nkmReMbH/JRgowBsbX2m7eoRLEgjjMu/Xg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'one?': 0.05; 'false,': 0.07; 'cc:addr:python-list': 0.09; 'arg': 0.09; 'handling,': 0.09; 'none.': 0.09; 'python': 0.10; 'def': 0.13; 'subject: \n ': 0.15; 'things.': 0.15; '"is"': 0.16; "(it's": 0.16; '2016': 0.16; ':))': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable': 0.16; 'iterator,': 0.16; 'object()': 0.16; 'received:209.85.223.173': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'byte': 0.18; "shouldn't": 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'sat,': 0.23; 'header:In- Reply-To:1': 0.24; 'checking': 0.27; 'message-id:@mail.gmail.com': 0.27; 'party,': 0.29; 'str': 0.29; 'objects': 0.29; 'checks': 0.30; 'anyone': 0.32; 'says': 0.32; 'common': 0.33; 'values.': 0.33; 'received:google.com': 0.35; 'text': 0.35; 'identity': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'late': 0.38; 'received:209': 0.38; 'where': 0.40; 'some': 0.40; 'care': 0.60; 'more': 0.63; 'necessarily': 0.63; 'mar': 0.65; '26,': 0.72; 'chrisa': 0.84; 'to:none': 0.91; 'thing,': 0.93; 'story.': 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; bh=OwvdbcMWd2AUmr7Pq5xnT99oWx/jXnkVkYBR2aDvrQg=; b=mAhYnKjnbqOUTqTj78M2OxN6vqsr9Qd/nU4et2KNXaZwLXRh0BZynPK6y0U+G6RPAT H9r3R1kJYxd1HIHciIQvRsGi3vBH+ntKV/Vqe6m9HyMKGMXz0SU3mSAiaGqUsv3ERi+z 1MtoQq2hYZIvaaTkEdmtfdvZLDN/Nf8rVO2ybNqasgZwona0do0Jnq0nT8LeEPaoM0QJ GibE2Ga5UBgWd2Nw/8Lzsoo+8sqmhrxPfGMbXw3+HFlK/iU1FnzRlVSEZExneyv785BO 1Evquc0pLlCIwLiyndZ/6DZq6OFHbtLiVUc+gMmHeQmyqk8Kh9GjE6SIUMEqFmyQ9gut uOnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=OwvdbcMWd2AUmr7Pq5xnT99oWx/jXnkVkYBR2aDvrQg=; b=fRdg/i4arT+mOLNcrKgsshpT2DADrcUgZLN2ZdVpZNtcOU1b1r4d1W6NhZ0qnrZh2x 4/gq6KFzhjzWgI+gIOa25VGu1dEaw2Yv7lSM4gUmtQx05Bs7/gcPYQCJzp+w0VYy5iNq oQPw8BlgrCzZni6t3uK4MNj6Q2b7fM0wmZizJLeauo1qJ73Saf842jMzXreC6en1Icti hv7mwG6jP3cwm7LHQegzuZmJEWA/WziBxR+Ch0gpGqOJ7rJwWYmVMgkRx0JIsrzcx0gH 32WVSDFu31J8WVAaHgt7L5xGpcmjJF/7MAOPDKdvfg7IMUgnslcldBRr1QMRTczubhPH +69g== X-Gm-Message-State: AD7BkJK6TKZTJFB1FEwtN0CxprYLUA0sn/xdTPFHXL8zdpN4o3wGacxDfcZiOIH4hZpZP+wzytlmp59wBQqMPw== X-Received: by 10.107.169.105 with SMTP id s102mr12909506ioe.19.1458912153459; Fri, 25 Mar 2016 06:22:33 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105688 On Sat, Mar 26, 2016 at 12:03 AM, Albert-Jan Roskam wrote: >> You should not bother with object identity for objects other than None. > > > A little late to the party, but: how about Ellipsis? Shouldn't "is" also be used for that one? (It's rare, I know :)) Yes, and also True and False, if you're checking for the specific values. (Though it's more common in Python to merely care about truthiness/falsiness.) Other common identity checks include: if str is bytes: # Python 2 handling, where "native strings" are byte strings else: # Python 3 handling, where "native strings" are text strings if iter(x) is x: # x is an iterator, not some other iterable _SENTINEL = object() def func(arg=_SENTINEL): if arg is _SENTINEL: # arg was not passed Anyone who says that identity checks are only for None is significantly over-simplifying things. This isn't necessarily a bad thing, but it should never be taken to be the whole story. ChrisA