Mark Dickinson added the comment:

While I agree that this isn't an exact duplicate of #3692, the underlying cause 
is the same, and Python is working as designed and documented in this case.

In Python 2, list comprehensions don't have their own scope, so the `x` in your 
initial example lives at class scope.  However, the set comprehension *does* 
have its own scope.  By design, a variable defined at class scope is not 
visible to inner scopes inside that class.

In Python 3, this works because the list comprehension has its own scope.

See the documentation here:

http://docs.python.org/2/reference/executionmodel.html#naming-and-binding

and the `class A` example in particular.

Reclosing: there's no way this behaviour going to change in Python 2, and this 
particular case is no longer an issue in Python 3.

----------
nosy: +mark.dickinson
resolution:  -> invalid
status: open -> closed

_______________________________________
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

Reply via email to