[New-bugs-announce] [issue5106] Update Naming & Binding statement for 3.0

Terry J. Reedy report at bugs.python.org
Fri Jan 30 04:50:24 CET 2009

New submission from Terry J. Reedy <tjreedy at udel.edu>:

Language / Execution Model / Naming & Binding 
just before example that does not work, 

class A:
    a = 42
    b = list(a + i for i in range(10))

says :
"The scope of names defined in a class block is limited to the class
block; it does not extend to the code blocks of methods – this includes
generator expressions since they are implemented using a function scope."

As pointed out by Alan Isaacs (clp), in 3.0,
"this includes comprehensions and generator expressions"
would be more complete and not possibly imply that g.e.s are special in
this regard.  In 2.x, 
    c = [a + i for i in range(10)]
works but it fails with same 
"NameError: global name 'a' is not defined"
in 3.0.  In fact, I think 'comprehensions and ' should be added just
because this is a change which people could trip over.

assignee: georg.brandl
components: Documentation
messages: 80810
nosy: georg.brandl, tjreedy
severity: normal
status: open
title: Update Naming & Binding statement for 3.0
versions: Python 3.0, Python 3.1

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list