Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'cpython': 0.05; 'differently': 0.07; 'referring': 0.07; 'variables': 0.07; 'exist,': 0.09; 'reference:': 0.09; 'variables.': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'bound,': 0.16; 'bound.': 0.16; 'created.': 0.16; 'raised.': 0.16; 'subclass': 0.16; 'exception': 0.16; 'sat,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'all,': 0.19; 'module': 0.19; 'python?': 0.22; 'cc:addr:python.org': 0.22; 'refers': 0.24; 'cc:2**0': 0.24; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'chris': 0.29; 'am,': 0.29; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; '(although': 0.31; 'slot': 0.31; 'says': 0.33; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'level': 0.37; 'fact': 0.38; 'pm,': 0.38; 'does': 0.39; 'skip:u 10': 0.60; 'referred': 0.60; 'tell': 0.60; 'simple': 0.61; 'name': 0.63; 'more': 0.64; 'compliant': 0.68; 'detail.': 0.68; 'sound': 0.68; 'ethan': 0.84; 'furman': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=uVXUXpRpImm9sGzGCbVlPideBfSmk7IhJByawc+i8Ao=; b=kL6drk7MYec9y66Ixrmy65rbDblJm5TSwOH3z4wlwEM60vVTUUSGxvq1q5CHCa+kOQ OOMBy+EnEQmYRmOGHxA+HOgHMIvhfejqkfkS6yxZ9iCpG+dmKplYUO48pPRkAyLRvmYx xLTvGzylKVUTefdzLEhLMpkFe3iXzcQrRSdvOBF1Rl2xN4uPFyIeRfAZbLCKqWiDJa2R +bNIpLDRVC5rG8AVDlUc3Rb44mVWaKgLaKvOpGxk0FNqQ29wzvSkxXSfHAl3sXU90g9O wB6idviUgKD35UnIU8ee9hSkHfQPxcAdq/OLUg3QtAYfTXMFr5A5pivHEIDUR1n0T2WD YhxA== X-Received: by 10.236.142.16 with SMTP id h16mr28574575yhj.2.1399755831855; Sat, 10 May 2014 14:03:51 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <536E799D.6080602@stoneleaf.us> References: <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> <5368681D.8070602@islandtraining.com> <87ppjpwafk.fsf@elektro.pacujo.net> <536ad8f2$0$29965$c3e8da3$5496439d@news.astraweb.com> <87zjiqbmy5.fsf@elektro.pacujo.net> <536d7a7d$0$29980$c3e8da3$5496439d@news.astraweb.com> <9cc0ebf9-dbed-4d3d-91fc-2abb9b0103d0@googlegroups.com> <536dc3f7$0$29980$c3e8da3$5496439d@news.astraweb.com> <536decca$0$29980$c3e8da3$5496439d@news.astraweb.com> <536E799D.6080602@stoneleaf.us> From: Devin Jeanpierre Date: Sat, 10 May 2014 14:03:11 -0700 Subject: Re: Values and objects To: Ethan Furman Content-Type: text/plain; charset=UTF-8 Cc: "comp.lang.python" 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1399757236 news.xs4all.nl 2971 [2001:888:2000:d::a6]:42210 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71275 On Sat, May 10, 2014 at 12:10 PM, Ethan Furman wrote: > On 05/10/2014 02:32 AM, Chris Angelico wrote: >> >> >> Tell me, what may this function do in a compliant Python? >> >> def demo(): >> ret = spam >> spam = 23 >> return ret >> >> In CPython, that'll raise UnboundLocalError, because the local >> variable 'spam' does already exist, and currently has no value (no >> object bound to it). > > > No, it does not exist -- or, more accurately, it does not exist *yet* but > will. The fact that there is a slot waiting for what will be spam is a > cpython implementation detail. The name of the exception is "UnboundLocalError". And the message says that we referred to a "local variable". Also see the language reference: "When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError." spam is referring to a local variable that has not been bound. This is not an implementation detail. > And if you don't like that argument (although it is a perfectly sound and > correct argument), think of the module name space: > > > ret = spam > spam = 23 > > will net you a simple NameError, because spam has not yet been created. Because module level variables work differently from local variables. -- Devin