Message190890
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. |
|
Date |
User |
Action |
Args |
2013-06-10 07:44:56 | mark.dickinson | set | recipients:
+ mark.dickinson, ezio.melotti, Eric.Wieser, dmi.baranov |
2013-06-10 07:44:56 | mark.dickinson | set | messageid: <1370850296.48.0.713649371452.issue18110@psf.upfronthosting.co.za> |
2013-06-10 07:44:56 | mark.dickinson | link | issue18110 messages |
2013-06-10 07:44:56 | mark.dickinson | create | |
|