Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
Checklist
- I am confident this is a bug in CPython, not a bug in a third-party project
- I have searched theCPython issue tracker,
and am confident this bug has not been reported before
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Output from running 'python -VV' on the command line:
Python 3.12.0rc1 (main, Aug 29 2023, 19:34:25) [Clang 12.0.5 (clang-1205.0.22.9)]
A clear and concise description of the bug:
In therelease notes for 3.12.0rc1 there is the following paragraph about comprehension inlining:
Comprehension iteration variables remain isolated; they don’t overwrite a variable of the same name in the outer scope, nor are they visible after the comprehension. This isolation is now maintained via stack/locals manipulation, not via separate function scope.
I found a case when a comprehension iteration variable overwrite a variable of the same name in the outer scope:
deffoo(value):try: {int(key):valueforkey,valueinvalue.items()}except:print(repr(value))# will print 'baz' instead of {'bar': 'baz'}foo({'bar':'baz'})
However, if you run this code outside of the function, isolation works:
value= {'bar':'baz'}try: {int(key):valueforkey,valueinvalue.items()}except:print(repr(value))# ok, it will print {'bar': 'baz'}
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done