Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'string': 0.09; 'exception.': 0.09; 'false,': 0.09; 'false.': 0.09; 'integers': 0.09; 'subject:None': 0.09; 'subject:string': 0.09; 'thrown': 0.09; 'typed': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'language.': 0.14; '16-bit': 0.16; '8-bit': 0.16; 'different,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sense,': 0.16; 'exception': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'string,': 0.24; 'helpful': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'characters': 0.30; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'equivalent.': 0.31; 'steven': 0.31; 'figure': 0.32; 'could': 0.34; 'knows': 0.35; 'received:google.com': 0.35; 'raising': 0.36; 'returning': 0.36; 'subject:?': 0.36; 'error.': 0.37; 'does': 0.39; 'even': 0.60; 'strictly': 0.61; "you'll": 0.62; 'instantly': 0.84; 'technically': 0.84; 'absolutely': 0.87; '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=f2RNoUYv9IIJTR+Ooxv9mvoc/pybD8ONkGUB2sjr98s=; b=i24evkGDI+6JF0Lx8wrWYX043Esl2GW3pDNtUX20bIlE7RFHyBAObkov4srDJ2K1W6 z4e+eetJBr5AXU7i2oXk/LTU531JiaoyJ1jm8nAEW1+MjkFXIckN94PNVAdmJeuazjof HV2p9OZsxqbb5YkEjlKrUP8aYWDJMV9VluhJf837Ssm/ZUoYUIqQY5UjJbShe3o0WEFO 5b3amV2aKWWyfECAXfUhlu+TvFPrEYJEDcxRPFtY/H+Bh2Boe7NYw1/3NWmi4VCrkD6Y tdhvM9IEYXAOjFHT0dA4HIo/1W4G9XXAnvkB8Y5EbCnP7sXpjTdgutrXj3BcW54FmEcl w5sw== MIME-Version: 1.0 X-Received: by 10.220.175.70 with SMTP id w6mr1283064vcz.72.1402331514360; Mon, 09 Jun 2014 09:31:54 -0700 (PDT) In-Reply-To: <5395dd57$0$29988$c3e8da3$5496439d@news.astraweb.com> References: <048960da-c132-407f-b1b3-4612a3dd7697@googlegroups.com> <5395dd57$0$29988$c3e8da3$5496439d@news.astraweb.com> Date: Tue, 10 Jun 2014 02:31:54 +1000 Subject: Re: None in string => TypeError? 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: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402331523 news.xs4all.nl 2905 [2001:888:2000:d::a6]:33001 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73049 On Tue, Jun 10, 2014 at 2:14 AM, Steven D'Aprano wrote: >> This is very Pythonic, Python is strictly typed language. There's no way >> None could possibly be "inside" a string, > > Then `None in some_string` could immediately return False, instead of > raising an exception. Note, by the way, that CPython does have some optimizations that immediately return False. If you ask if a 16-bit string is in an 8-bit string, eg "\u1234" in "asdf", it knows instantly that it cannot possibly be, and it just returns false. The "None in string" check is different, and deliberately so. I do prefer the thrown error. Some things make absolutely no sense, and even if it's technically valid to say "No, the integer 61 is not in the string 'asdf'", it's likely to be helpful to someone who thinks that characters and integers are equivalent. You'll get an exception immediately, instead of trying to figure out why it's returning False. ChrisA