Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '16,': 0.03; 'cpython': 0.05; 'versions,': 0.05; 'objects,': 0.07; 'type,': 0.07; 'happen.': 0.09; 'str,': 0.09; 'subject:None': 0.09; 'aug': 0.13; '(note:': 0.16; "3.2's": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:type': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'thu,': 0.17; 'examples': 0.18; '>>>': 0.18; 'received:209.85.214.174': 0.21; 'int,': 0.22; 'header:In- Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'actual': 0.28; 'equivalent.': 0.29; 'str': 0.29; 'idle': 0.33; 'int': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'built-in': 0.35; 'false': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'compare': 0.36; 'two': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'guaranteed': 0.76; 'etc,': 0.84 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=1UyqqjGLChpJgoHY8+3Igb3zj7P+Y4Fd8ixBrX8NKO0=; b=hnY8b/irQEsKcA6omvLLLaSE6mu6GQbvVRpbXD86ZZ/zmFhWa5+rwJh2g7477k8ziK zJZLj42F5UlmmYXpVhquJL6SzZq/5ASsRp04VWCoVsXdw1ad0fgjPGec1rF3rkK9VBZc 2CSG5D91WB1w7uN4nxeYqRUJ02Sg1kXUJn5a72PEGG7t2UecniDcrsqKm82DEeachsgt 4HJbwfPmSgQ80EKIlca43bDOwRpPrOVqMX9ocZCGvYTBjgTDO/kBS093/0iLZcZJM3J3 juC1DuYQ1YEeMoLZBHNaO61JJ0FxcG+bi1pJqqW08qwE539bI11QroeRh3xE0TGA5WKN U8sA== MIME-Version: 1.0 In-Reply-To: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> References: <502cebf4$0$6905$e4fe514c@news2.news.xs4all.nl> Date: Thu, 16 Aug 2012 23:37:50 +1000 Subject: Re: type(None)() 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.12 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: 1345124274 news.xs4all.nl 6986 [2001:888:2000:d::a6]:52561 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27161 On Thu, Aug 16, 2012 at 10:47 PM, Hans Mulder wrote: > Why doesn't it just return an existing instance of the type, > like bool, int, str and other built-in non-mutable types do? > >> py> type(False)() is False >> True With int and str, it's only an optimization, and not guaranteed to happen. >>> a=int("1234") >>> a is int("1234") False >>> a=str(1234) >>> a is str(1234) False But with bool, it's required, as a means of "casting to boolean". With True/False/None, it's normal to compare them with is: >>> a=bool("1") >>> a is bool("2") True So bool() has to return one of those two actual objects, and not an equivalent. (Note: All examples done in CPython 3.2's IDLE on Windows. Other environments, Pythons, versions, etc, may affect exactly what these show.) ChrisA