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

frame.f_locals for list/dict/set comprehension in module/class scope doesn't contain iteration variables #108732

Closed
Assignees
carljm
Labels
type-bugAn unexpected behavior, bug, or error
@chgnrdv

Description

@chgnrdv

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:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.0a0 (heads/main:dd32611f4f, Aug 31 2023, 20:23:23) [GCC 10.2.1 20210110]

A clear and concise description of the bug:

The following assertion fails with PEP 709 (c3b595e):

importsysf_locs=None[f_locs:=sys._getframe().f_localsforainrange(1)]assert'a'inf_locs

This was discovered when trying to inspect listcomp iteration variable underpdb, as it makes inspection of these variables impossible:

> /home/radislav/projects/cpython/listcomp.py(1)<module>()-> [print(a) for a in range(1)](Pdb) s0> /home/radislav/projects/cpython/listcomp.py(1)<module>()-> [print(a) for a in range(1)](Pdb) print(a)*** NameError: name 'a' is not defined(Pdb) s/home/radislav/projects/cpython/listcomp.py:1: RuntimeWarning: assigning None to unbound local 'a'  [print(a) for a in range(1)]--Return--> /home/radislav/projects/cpython/listcomp.py(1)<module>()->None-> [print(a) for a in range(1)]

As I can see, it happens because iteration vars are now stored in "fast hidden locals" that aren't included intoframe->f_locals on_PyFrame_FastToLocalsWithError(frame) call, and thus are not accessible throughPyFrameObjectf_locals attribute.

cc@carljm

Linked PRs

Metadata

Metadata

Assignees

Labels

type-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