Author mark.dickinson
Recipients Eric.Wieser, dmi.baranov, ezio.melotti, mark.dickinson
Date 2013-06-10.07:44:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:

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:56mark.dickinsonsetrecipients: + mark.dickinson, ezio.melotti, Eric.Wieser, dmi.baranov
2013-06-10 07:44:56mark.dickinsonsetmessageid: <>
2013-06-10 07:44:56mark.dickinsonlinkissue18110 messages
2013-06-10 07:44:56mark.dickinsoncreate