[Feature Request]: Inline comprehensions (PEP 709) so that `eval()` / `exec()` / `locals()` inside one see the enclosing function's locals

オープン
#1,362 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
12/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
java, python
領域
compilers

調査の方向性

The payload names no source files, so begin by running the two snippets from the issue on GraalPy and on CPython 3.12+ to confirm the mismatch in eval(), exec() and locals() inside a comprehension. The work is compiler-level: comprehensions must share the enclosing function's scope, as PEP 709 specifies. Done means the three rows of the issue's table match CPython output.

索引モデルが issue の本文から書いたものです。

説明

enhancement
Describe the feature

List, set and dict comprehensions are compiled as separate code units, so eval(), exec() and locals() inside a comprehension in a function do not see the function's locals. CPython inlines these comprehensions since 3.12 (PEP 709). Seen on master 3289197e63 (Python 3.13.14) on macOS ARM64.

import sys

def f():
    a = 'abc'
    return [eval('a') for _ in range(1)]

def g():
    a = 'abc'
    return [sys._getframe().f_code.co_name for _ in range(1)]
Expression GraalPy CPython
f() NameError: name 'a' is not defined ['abc']
eval("(lambda a: [eval('a') for _ in range(1)])('abc')") NameError: name 'a' is not defined ['abc']
g() ['<listcomp>'] ['g']
Expected behavior

The CPython column above (3.12.13 and 3.13.14).

Additional context

No response

主要言語
Python
スター
1.7k
フォーク
167
平均マージ
3日 11時間
マージ済み PR(30日)
68

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

oracle/graalpython のほかの issue

oracle/graalpython の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。