Issue 5106: Update Naming & Binding statement for 3.0 (original) (raw)

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.