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

Created on 2012-04-11 04:46 by ncoghlan, last changed 2012-04-13 17:18 by terry.reedy.

Messages (3)
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:
Date User Action Args
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