python / python/cpython

tarfile.TarFile.next() adds an unnecessary traceback frame when reraising exceptions

未關閉
#149,760 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

description:

https://gist.github.com/devdanzin/f8af359770ff200eac8474de5644be82

tarfile.TarFile.next() currently reraises non-zlib exceptions with raise e
inside its generic exception handler:

except Exception as e:
    try:
        import zlib
        if isinstance(e, zlib.error):
            raise ReadError(f'zlib error: {e}') from None
        else:
            raise e
    except ImportError:
        raise e

Using raise e adds an extra traceback frame at the re-raise site. A bare
raise would keep the traceback cleaner while preserving the original exception
and its traceback.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Windows

Linked PRs
  • gh-149761
  • gh-157257

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

在 tarfile 模組中搜尋 TarFile.next(),並檢查 issue 中顯示的泛用例外處理器。確認連結 gist 中描述的 traceback 差異,然後在完成例外處理變更後執行 tarfile 測試,以驗證非 zlib 例外保留其原始 traceback,且 zlib 錯誤維持不變。

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

評估

技術堆疊
python
領域
backend
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
35/100

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

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