Title: Limit "global" keyword name conflicts in language spec to those enforced by CPython
Type: enhancement Stage: needs patch
Components: Versions: Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alex, cvrebert, eric.araujo, ezio.melotti, fossilet, ncoghlan, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2012-04-11 04:46 by ncoghlan, last changed 2015-03-05 10:03 by ezio.melotti.

Messages (4)
msg158005 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-04-11 04:46
The language spec currently includes the following paragraph [1]:

   Names listed in a global statement must not be defined as
   formal parameters or in a for loop control target, class
   definition, function definition, or import statement.

While the first restriction is real (and enforced by CPython), since formal parameters are explicitly defined as local variables, there's no obvious rationale for the last 4 restrictions (and CPython doesn't enforce any of them).

The proposal is that the paragraph be simplified to:

   Names listed in a global statement must not also be defined as
   formal function parameters. Attempting to do so raises SyntaxError.

The current (incorrect!) CPython implementation detail note will be removed.

A similar clarification will also be made in the "nonlocal" statement documentation.

msg158006 - (view) Author: Alex Gaynor (alex) * (Python committer) Date: 2012-04-11 04:51
This shouldn't be a problem for PyPy, in fact I'm almost positive that we implement this already (since Django has a test that uses this "feature").  If/when the spec is changed please make sure there are tests for all these cases so we *know* it works though.
msg158007 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-04-11 04:52
Thread link:
msg237252 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-03-05 09:29
+1 for the proposed change.   It should add there is also an enforced (and obvious) restriction that the variable not have been declared nonlocal.
Date User Action Args
2015-03-05 10:03:11ezio.melottisetnosy: + ezio.melotti
stage: needs patch

versions: + Python 3.5, - Python 3.3
2015-03-05 09:29:58rhettingersetnosy: + rhettinger
messages: + msg237252
2015-03-05 08:51:06fossiletsetnosy: + fossilet
2012-04-13 17:18:24terry.reedysetnosy: + terry.reedy
2012-04-11 05:28:54cvrebertsetnosy: + cvrebert
2012-04-11 05:03:36eric.araujosetnosy: + eric.araujo
2012-04-11 04:52:27ncoghlansetmessages: + msg158007
2012-04-11 04:51:52alexsetnosy: + alex
messages: + msg158006
2012-04-11 04:46:30ncoghlancreate