More programmatic access to error locations in the traceback module

Aberta
#98,709 1 comentário 2 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Funcionalidade
Clareza
Razoavelmente clara
Status de atividade
Estagnada
Stack de tecnologia
python
Domínio
devtools

Direção de pesquisa

Comece em Lib/traceback.py, em format_frame_summary(), onde é descrita a lógica existente para localizações detalhadas do traceback. Determine como essa lógica poderia ser separada para expor os números de coluna para formatação personalizada do traceback sem analisar a string retornada. Considera-se concluído quando os chamadores puderem acessar as localizações programaticamente, preservando a saída existente do traceback.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

stdlib type-feature

Feature or enhancement

I'd like for the traceback module to have a more programmatic way to access the fine-grained error locations that are printed in tracebacks starting in Python 3.11 (PEP 657).

Pitch

The new fine-grained error information in tracebacks is nice. But I'd like to be able to write a custom traceback printer that uses this information and prints it in a different way (I'd like to highlight the characters in the lines of source rather than having ASCII characters under them).

The logic for getting the locations of the printed fine-grained information is present in the traceback module, but unfortunately, it's only present inside of the format_frame_summary() method, which returns a string. That means that to access the information, I have to parse the string.

It would be convenient if the logic in that method were separated out into a separate method that returned the column numbers, so that it could be called from a superclass. I would be fine if this method is private, so that it wouldn't strictly speaking add a new API or hard-code the existing traceback information into the API.

Previous discussion

I haven't followed the discussions on PEP 657 so I don't know if this has been discussed previously. I don't see any mention of the traceback module in the PEP.

Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Merge médio
1d 9h
PRs com merge (30d)
558

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.