[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Changes by Éric Araujo mer...@netwok.org: -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Changes by Daniel Urban urban.dani...@gmail.com: -- nosy: +durban ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Jonathan Hartley tart...@tartley.com added the comment: Is also exhibited by other class variable being used in the 'output' clause of the list comprehension: class C: ... x = 3 ... z = [z*x for z in range(4)] Traceback (most recent call last): File stdin, line 1, in module File stdin, line 3, in C File stdin, line 3, in listcomp -- nosy: +jonathan.hartley versions: +Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Changes by Andreas Stührk andy-pyt...@hammerhartes.de: -- nosy: +Trundle ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Terry J. Reedy tjre...@udel.edu added the comment: Devs are aware that there is an exception to the general rule for the 'for' clause. There is a technical reason why the exception is possible, though I have forgotten it. Since you already know that changing the general behavior has been rejected, are you asking that the exception be removed (for consistency) , so that your first example would fail? If so, that will be rejected also. I am changing this to a doc issue in case you or someone else wishes to suggest a doc improvement. The solution to the limitation on generator expressions, of course, is to write out the generator one is trying to abbreviate. def clipper(max): for i in range(5): if i max: yield i class Foo: x = 3 y = list(clipper(x)) print(Foo.y) # [0, 1, 2] -- assignee: - docs@python components: +Documentation -Interpreter Core nosy: +docs@python, terry.reedy stage: - needs patch versions: +Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
New submission from Menno Smits me...@freshfoo.com: A list comprehension or generator expression in a class definition fails with NameError if it has a condition that refers to another class variable. This doesn't occur if the class variable is used the in part of the expression. The following works: class Foo: x = range(3) y = [z for z in x] but this doesn't: class Foo: x = 3 y = [z for z in range(5) if z x] The error reported is: NameError: global name 'x' is not defined Both of these examples work in Python 2. Issue3692 suggests that class variables can't be referred to inside list comprehensions and gen expressions inside class definitions and that this won't be fixed, but these examples show that it is possible to refer to an outside class variable depending on usage. This is inconsistent and confusing. The Python 2 behaviour makes much more sense. I understand that we don't want list comprehensions to leak internal variables but they should still be able to pull names from outside scopes in a consistent way. -- components: Interpreter Core messages: 133213 nosy: mjs0 priority: normal severity: normal status: open title: list and generator expressions in a class definition fail if expression condition refers to a class variable type: behavior versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11796 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com