inlined comprehension and closed over variables have buggy interactions
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece executando o reprodutor fornecido /tmp/bug.py no CPython main e comparando-o com o Python 3.11. Leia a interação com issue #124697 e o PR vinculado gh-156691 antes de investigar. Está concluído quando o exemplo retornar [3] sem UnboundLocalError, preservando o comportamento de comprehensions inline.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- compilers
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100