Exceptions raised while tracing certain statements cannot be caught
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
So I found a really odd bug today. except blocks don't catch exceptions raised when tracing certain statements that themselves "cannot raise". For example:
def f():
breakpoint()
try:
pass # If you raise while tracing this line, the exception isn't caught.
except:
...
try:
42 # Ditto.
except:
...
try:
return # Ditto.
except:
...
A couple of observations:
- Exceptions raised while tracing other "normal" statements are handled the normal way.
- The code for the exception handling is still present in these examples, even though it's statically unreachable.
- If two or more of these "non-raising" statements occur together in the same block (like several
passstatements in a row), only the last one will have the bug:
def f():
breakpoint()
try:
pass # No bug
pass # No bug
pass # Bug
except:
...
I haven't invested any time into figuring out what the root cause is, I've just been poking at it with code examples. It's definitely a bug in the bytecode compiler though, not the interpreter (dis shows missing exception table entries). Probably something to do with how we emit exception tables for NOP or anything that unwinds the block stack, if I had to guess?
(This also affects 3.12, and maybe even earlier versions, but only tagging for 3.13 and newer since I don't think this is a "security" issue.)
Linked PRs
- gh-148333
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
Reproduza os exemplos na issue e inspecione sua saída de dis, concentrando-se nas entradas ausentes da tabela de exceções para pass, 42 e return. Compare esses casos com o tracing de instruções normais e examine o tratamento de NOP e o desenrolamento da pilha de blocos pelo compilador. Considera-se concluído quando os blocos except capturam as exceções geradas durante o tracing dessas instruções, com cobertura de regressão para os casos descritos.
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
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100