Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'tests.': 0.07; 'immutable': 0.09; 'integers': 0.09; 'strings.': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'mostly': 0.14; "wouldn't": 0.14; 'argument:': 0.16; 'boundaries,': 0.16; 'cares': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'kern': 0.16; 'mutable': 0.16; 'object()': 0.16; 'recognizing': 0.16; 'sentinel': 0.16; 'singleton': 0.16; 'sure.': 0.16; 'uses,': 0.16; 'wrote:': 0.18; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'cc:2**0': 0.24; 'equivalent': 0.26; 'header:In- Reply-To:1': 0.27; 'point': 0.28; "we'd": 0.29; 'am,': 0.29; 'robert': 0.30; 'message-id:@mail.gmail.com': 0.30; 'object.': 0.31; 'fri,': 0.33; 'could': 0.34; 'problem': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'object,': 0.36; 'being': 0.38; 'same.': 0.38; 'serving': 0.60; 'new': 0.61; 'such': 0.63; 'our': 0.64; 'more': 0.64; 'different': 0.65; 'nobody': 0.68; 'around,': 0.84; 'to:none': 0.92 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=NMndpgiASS0hWSuu6U49j/wR42x7bFAOKVPUxhlOCmg=; b=c+1Z3qbDOgeKV1azkewwbu3RHBDa05xi06jSXhoKJm0/rdy/DYrD3Pa7F1ka994aUE 0kdnKZx6YhnYzUTi3CGXyXLHV10vAROI8FE0VYiAb0xR96DaRXTCvdhH8CxyB4o1rEFA 2pT/0WKyXHDhh5w+TPaR7kJ2sIayAJ9HY+ybpCYvTA0KfoO+X1fKTelgi80CEF+4co78 ruU8P1MZSryIg6sZRnwzFWB4+lrd4KcvP2xND/nkmcB68+nSiIXmEUYZS47yW6aM0kcL lNudQlqriNSrW/p3yOx4l6ta2s2lxcghlyl5xSUMt1FOAAktxXld0uPRjEj6bMHA13ob zWDQ== MIME-Version: 1.0 X-Received: by 10.66.26.176 with SMTP id m16mr4366366pag.142.1392326869903; Thu, 13 Feb 2014 13:27:49 -0800 (PST) In-Reply-To: References: Date: Fri, 14 Feb 2014 08:27:49 +1100 Subject: Re: singleton ... again 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.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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392326879 news.xs4all.nl 2957 [2001:888:2000:d::a6]:38364 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:66251 On Fri, Feb 14, 2014 at 8:13 AM, Robert Kern wrote: > We don't use `is None` instead of `== None` for the speed. We use it for > robustness. We don't want arbitrary __eq__()s to interfere with our sentinel > tests. If None weren't a singleton that we could use as such a sentinel, > we'd make one. Sure. Yes, its identity is important as part of its being the Python equivalent of C's null pointer. But the main point of singletons is to be able to be "instantiated" without creating new elements; the sentinel status of None is no different from the classic way of recognizing the presence of an argument: _SENTINEL = object() def foo(arg1, arg2=_SENTINEL): if arg2 is not _SENTINEL: do_stuff_with(arg2) That's not a singleton in that sense; it's just a unique object. You could use [] for that instead of object() and it would work just the same. So None is serving multiple purposes: it's an empty object, but it's also a sentinel. In many uses, it wouldn't be a problem to have more Nones floating around, hence it's mostly like your classic singleton. My main point about mutable vs immutable is more clearly seen with integers and strings. Some integers are cached; some strings are interned; nobody particularly cares about the exact boundaries, except when playing around with id() or introspection of some sort. ChrisA