repr(PermissionError) lacks filename information
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
repr(PermissionError) looses the information about the affected filename, because it only returns PermissionError(13, 'Permission denied'). Example code to demonstrate that (run as non-root):
#!/usr/bin/python3
try:
open("/path-with-no-write-access", "w")
except PermissionError as error:
print(f"error = {error}")
print(f"eval(repr(error)) = {eval(repr(error))}")
Output of this code:
error = [Errno 13] Permission denied: '/path-with-no-write-access'
eval(repr(error)) = [Errno 13] Permission denied
I also failed to figure out how to raise a PermissionError with a filename specified. PermissionError takes no keyword arguments.
Rational
apport uses repr(error) in UserInterface.collect_info() in case the thread_collect_info thread crashes to present this information to the user. One test case failed with PermissionError(13, 'Permission denied') which did not help at all to trouble shoot the failure. If the representation of the exception had included the filename, it would have saved me time.
Your environment
- CPython versions tested on: 3.10.4
- Operating system and architecture: Ubuntu 22.04 LTS (jammy)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先,在沒有 root 權限的系統上重現已回報的 PermissionError 範例,並檢查 PermissionError 如何儲存及格式化其 filename。追蹤例外表示方式以及針對 OSError 子類別的現有測試,然後新增覆蓋範圍,顯示 repr 中所需的 filename 資訊,同時在適用時保留 eval(repr(error)) 的行為。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100