More programmatic access to error locations in the traceback module

未關閉
#98,709 1 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python
領域
devtools

研究方向

從 Lib/traceback.py 中的 format_frame_summary() 開始,這裡描述了現有的細粒度 traceback 位置邏輯。確定如何分離該邏輯,以便在不解析回傳字串的情況下,為自訂 traceback 格式化提供欄號。完成的標準是呼叫端可以透過程式存取這些位置,同時保留現有的 traceback 輸出。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python/cpython 的其他 Issue

查看 python/cpython 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。