Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit "global" keyword name conflicts in language spec to those enforced by CPython #58749

Open
ncoghlan opened this issue Apr 11, 2012 · 4 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

BPO 14544
Nosy @rhettinger, @terryjreedy, @ncoghlan, @ezio-melotti, @merwok, @alex

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2012-04-11.04:46:30.833>
labels = ['type-feature']
title = 'Limit "global" keyword name conflicts in language spec to those enforced by CPython'
updated_at = <Date 2015-03-05.10:03:11.434>
user = 'https://github.com/ncoghlan'

bugs.python.org fields:

activity = <Date 2015-03-05.10:03:11.434>
actor = 'ezio.melotti'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = []
creation = <Date 2012-04-11.04:46:30.833>
creator = 'ncoghlan'
dependencies = []
files = []
hgrepos = []
issue_num = 14544
keywords = []
message_count = 4.0
messages = ['158005', '158006', '158007', '237252']
nosy_count = 8.0
nosy_names = ['rhettinger', 'terry.reedy', 'ncoghlan', 'fossilet', 'ezio.melotti', 'eric.araujo', 'alex', 'cvrebert']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue14544'
versions = ['Python 3.5']

@ncoghlan
Copy link
Contributor Author

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.

[1] http://docs.python.org/dev/reference/simple_stmts.html#the-global-statement

@ncoghlan ncoghlan added the type-feature A feature request or enhancement label Apr 11, 2012
@alex
Copy link
Member

alex commented Apr 11, 2012

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.

@ncoghlan
Copy link
Contributor Author

@rhettinger
Copy link
Contributor

+1 for the proposed change. It should add there is also an enforced (and obvious) restriction that the variable not have been declared nonlocal.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added docs Documentation in the Doc dir 3.11 only security fixes easy 3.12 bugs and security fixes 3.13 bugs and security fixes labels May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 bugs and security fixes docs Documentation in the Doc dir easy type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants