-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
List comprehensions now have access to the enclosing class scope #104374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
I don't think so. I just confirmed on 3.10.9 (don't have a 3.10.8 around), and it throws a NameError. Make sure you run the sample in a class scope. |
sorry, you're right! - I forgot to restart the interpreter when testing different variations - so there was already a |
I started a Discourse thread about options for handling this: https://discuss.python.org/t/pep-709-one-behavior-change-that-was-missed-in-the-pep/26691 |
I filed a SC issue about this: python/steering-council#189 |
…104528) Co-authored-by: Carl Meyer <carl@oddbird.net>
Code:
On current main:
But on 3.11:
I actually like the new behavior, and I discovered this bug as I was preparing a post proposing that we make things work this way in 3.13. But it's a behavior change, and we should only make this change on purpose and not by accident.
This could plausibly break real code if the name is defined in both the module and class scope, and current code relies on getting the name from the module scope.
cc @carljm
Linked PRs
The text was updated successfully, but these errors were encountered: