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

UnboundLocalError when module is shadowed by a comprehension and then accessed by another comprehension #118513

Closed
Labels
3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error
@jmymay

Description

@jmymay

Bug report

Bug description:

Seems to be a regression in 3.12 when compared to 3.11, likely caused byPEP 709: Comprehension inlining, but I haven't verified this. Example below. (Noticed while runningthis code.)

importsysdeff():_= [sysforsysin []]# can be any module other than sys    [sys.stdout.write('success\n')for_in [1]]f()
$ python3.11 main.py  # 3.11.9success
$ python3.12 main.py  # 3.12.3Traceback (most recent call last):  File "/home/jkozera/imp/main.py", line 5, in <module>    f()  File "/home/jkozera/imp/main.py", line 4, in f    [sys.stdout.write('success\n') for _ in [1]]     ^^^UnboundLocalError: cannot access local variable 'sys' where it is not associated with a value
$ python3.13 main.py  # 3.13.0a6+ (heads/main:2770d5c, May  2 2024, 18:19:03)Traceback (most recent call last):  File "/home/jkozera/imp/main.py", line 5, in <module>    f()    ~^^  File "/home/jkozera/imp/main.py", line 4, in f    [sys.stdout.write('success\n') for _ in [1]]     ^^^UnboundLocalError: cannot access local variable 'sys' where it is not associated with a value

CPython versions tested on:

3.11, 3.12, CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp