Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comprehension iteration variable overwrite a variable of the same name in the outer scope inside a function with try..except #108654

Closed
Assignees
carljm
Labels
3.12only security fixes3.13bugs and security fixesrelease-blockertype-bugAn unexpected behavior, bug, or error
@Fatal1ty

Description

@Fatal1ty

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

3.12only security fixes3.13bugs and security fixesrelease-blockertype-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp