inlined comprehension and closed over variables have buggy interactions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo il riproduttore fornito /tmp/bug.py su CPython main e confrontalo con Python 3.11. Leggi l’interazione con issue #124697 e la PR collegata gh-156691 prima di indagare. Il lavoro è completato quando l’esempio restituisce [3] senza UnboundLocalError, preservando al contempo il comportamento delle comprehensions inline.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100