This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <1370850296.48.0.713649371452.issue18110@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
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: <1370850296.48.0.713649371452.issue18110@psf.upfronthosting.co.za>
2013-06-10 07:44:56mark.dickinsonlinkissue18110 messages
2013-06-10 07:44:56mark.dickinsoncreate