Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'cpython': 0.05; 'abuse': 0.07; 'python3': 0.07; 'definition,': 0.09; 'freedom,': 0.09; 'parameter': 0.09; 'restriction': 0.09; 'target,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; '2.7.3': 0.16; '2.7:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'likewise': 0.16; 'statement.': 0.16; 'subject:bound': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'either.': 0.24; 'cc:2**0': 0.24; 'defined': 0.27; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'dec': 0.30; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; '"",': 0.31; "d'aprano": 0.31; 'enforce': 0.31; 'steven': 0.31; 'subject:what': 0.31; 'file': 0.32; 'class': 0.32; 'linux': 0.33; 'url:python': 0.33; 'fri,': 0.33; 'but': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'nov': 0.38; 'pm,': 0.38; 'does': 0.39; 'future': 0.60; 'url:3': 0.61; 'first': 0.61; 'name': 0.63; 'subject:The': 0.64; 'more': 0.64; 'mar': 0.68; '2014,': 0.84; 'silently': 0.84; 'subject:gets': 0.84; 'url:reference': 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=rfM5xtyY9H3KBEbw/fH5qcMc43stNw0d/cKqGpGfpyY=; b=AYYcI+iLVYlAIrTOIMneRf7kSFJ7JC7RSAOYtisKZACzgjJNnqE9ySmNMcukNRm8/6 6+fhtBZI7JennnFWL8lBKctXAXTg8+b3stMcL3euEA3UMVdrgtSOakf9Plknx6xewrmK gZ73fYovFIEfqOPSovw3E8E5BvFA3t3lALqIpUT2ugORNH+KPRE5A9iPTnO6bE4BWInB Q+oiiZGqQBeCKjnfc5pG6dNzKbHjj9pHYVX5ncdqWJ25BF6kPGNF2bXmEidgrevApDL6 MqB8umIsVlLtjWcCrdH2dwpX2CfLpRRrbx0x+0Jog6r1QZvvPe50CAUaH3xJXynbIMLS RpYA== MIME-Version: 1.0 X-Received: by 10.50.62.104 with SMTP id x8mr2244334igr.2.1417783704466; Fri, 05 Dec 2014 04:48:24 -0800 (PST) In-Reply-To: <5481a63d$0$12992$c3e8da3$5496439d@news.astraweb.com> References: <548113f3$0$13003$c3e8da3$5496439d@news.astraweb.com> <548180ae$0$13007$c3e8da3$5496439d@news.astraweb.com> <5481a63d$0$12992$c3e8da3$5496439d@news.astraweb.com> Date: Fri, 5 Dec 2014 23:48:24 +1100 Subject: Re: The binding operator, and what gets bound to what 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417783712 news.xs4all.nl 2977 [2001:888:2000:d::a6]:48503 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82002 On Fri, Dec 5, 2014 at 11:34 PM, Steven D'Aprano wrote: >> I don't think this is implementation-dependent. > > The docs say that it is: > > https://docs.python.org/3/reference/simple_stmts.html#the-global-statement > > Names listed in a global statement MUST NOT [emphasis added] be > defined as formal parameters or in a for loop control target, > class definition, function definition, or import statement. > > CPython implementation detail: The current implementation does not > enforce the two restrictions, but programs should not abuse this > freedom, as future implementations may enforce them or silently > change the meaning of the program. Interesting, I didn't know that either. But the first restriction _is_ enforced: rosuav@sikorsky:~$ python3 Python 3.5.0a0 (default:23ab1197df0b, Nov 20 2014, 12:57:44) [GCC 4.7.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def x(y): ... global y ... File "", line 2 SyntaxError: name 'y' is parameter and global Likewise in CPython 2.7: rosuav@sikorsky:~$ python Python 2.7.3 (default, Mar 13 2014, 11:03:55) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def x(y): ... global y ... File "", line 1 SyntaxError: name 'y' is local and global ChrisA