inlined comprehension and closed over variables have buggy interactions
オープン
まだ誰も着手していません。
interpreter-core
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
We are a bit late to report this, but the following of PyPy's unit tests got broken by inlined comprehensions in CPython 3.12:
def test_inlined_comprehension_private_name_reuse():
x = 3
def f():
[x for x in [1]]
return [x for _ in [1]]
assert f() == [3]
test_inlined_comprehension_private_name_reuse()
this passes fine in CPython 3.11 but breaks like this in 3.12 onwards, including on main:
$ ./python /tmp/bug.py
Traceback (most recent call last):
File "/tmp/bug.py", line 10, in <module>
test_inlined_comprehension_private_name_reuse()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/tmp/bug.py", line 8, in test_inlined_comprehension_private_name_reuse
assert f() == [3]
~^^
File "/tmp/bug.py", line 6, in f
return [x for _ in [1]]
^
UnboundLocalError: cannot access local variable 'x' where it is not associated with a value
I wonder whether that is the kind of bug that would be easier to fix when doing #124697
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-156691
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された再現スクリプト /tmp/bug.py を CPython main で実行し、Python 3.11 と比較します。調査する前に、issue #124697 とのやり取りと、リンクされた PR gh-156691 を読んでください。例が UnboundLocalError なしで [3] を返し、インライン化された内包表記の動作を維持できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100