[Python-3000] Change to class construction?
Phillip J. Eby
pje at telecommunity.com
Fri Jul 6 19:25:10 CEST 2007
At 05:00 PM 7/6/2007 +0200, Georg Brandl wrote:
>Collin Winter schrieb:
> > While experimenting with porting setuptools to py3k (as of r56155), I
> > ran into this situation:
> >
> > class C:
> > a = (4, 5)
> > b = [c for c in range(2) if a]
> >
> > results in a "NameError: global name 'a' is not defined" error, while
> >
> > class C:
> > a = (4, 5)
> > b = [c for c in a]
> >
> > works fine. This gives the same error as above:
> >
> > class C:
> > a = (4, 5)
> > b = [a for c in range(2)]
> >
> > Both now-erroneous snippets work in 2.5.1. Was this change intentional?
>
>It is at least intentional in the sense that in 3k it works the same as with
>genexps, which give the same errors in 2.5.
This looks like a bug to me. A list comprehension's local scope
should be the locals of the enclosing code, even if its loop indexes
aren't exposed to that scope.
More information about the Python-3000
mailing list