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)
]