[docs] [issue11796] list and generator expressions in a class definition fail if expression condition refers to a class variable
Terry J. Reedy
report at bugs.python.org
Sat Apr 9 02:22:10 CEST 2011
Terry J. Reedy <tjreedy at 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 at python
components: +Documentation -Interpreter Core
nosy: +docs at python, terry.reedy
stage: -> needs patch
versions: +Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11796>
_______________________________________
More information about the docs
mailing list