python / python/cpython

repr(PermissionError) lacks filename information

オープン
#92,921 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core type-feature
主要言語
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)

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、root 権限のないシステムで報告された PermissionError の例を再現し、PermissionError が filename をどのように保存およびフォーマットするかを調べます。例外の表現と OSError サブクラスに対する既存のテストを追跡し、その後、該当する場合は eval(repr(error)) の動作を維持しながら、repr に目的の filename 情報が表示されることを示すカバレッジを追加します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。