Author Eric.Wieser
Recipients Eric.Wieser
Date 2013-05-31.22:22:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1370038928.9.0.337300237862.issue18110@psf.upfronthosting.co.za>
In-reply-to
Content
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)
        ]
History
Date User Action Args
2013-05-31 22:22:08Eric.Wiesersetrecipients: + Eric.Wieser
2013-05-31 22:22:08Eric.Wiesersetmessageid: <1370038928.9.0.337300237862.issue18110@psf.upfronthosting.co.za>
2013-05-31 22:22:08Eric.Wieserlinkissue18110 messages
2013-05-31 22:22:08Eric.Wiesercreate