New submission from Eric Wieser: This code:
class Sudoku(dict): COLUMNS = [ {(x, y) for y in xrange(9)} for x in xrange(9) ] When run on Python 2.7.5, fails with this traceback: Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> class Sudoku(object): File "<pyshell#3>", line 3, in Sudoku {(x, y) for y in xrange(9)} for x in xrange(9) File "<pyshell#3>", line 3, in <setcomp> {(x, y) for y in xrange(9)} for x in xrange(9) NameError: global name 'x' is not defined Yet `x` is clearly not a global - it's defined in the comprehension. Running the comprehension outside of the class gives no error: >>> [ {(x, y) for y in xrange(9)} for x in xrange(9) ] [set([...]), ...] Nor does using `set`: class Sudoku(dict): COLUMNS = [ set((x, y) for y in xrange(9)) for x in xrange(9) ] ---------- components: Interpreter Core messages: 190420 nosy: Eric.Wieser priority: normal severity: normal status: open title: Nested set comprehensions in class scope fail type: behavior versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18110> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com