subprocess: `CalledProcessError.__str__` crashes when returncode is None
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Calling str() on a CalledProcessError crashes if its returncode is None.
The __str__ method uses if self.returncode and self.returncode < 0 for the "died with a signal" case, and otherwise formats the return code with %d. When returncode is None, that first check is falsy, so it falls through to the %d branch, and %d can't format None, so it raises TypeError. Having the exception's own string representation blow up is a pretty bad way to fail.
import subprocess
err = subprocess.CalledProcessError(None, "cmd")
str(err) # TypeError: %d format: a real number is required, not NoneType
The fix is to check for returncode is None before the %d branch and return a plain message instead.
Found while going through devdanzin's audit of the standard library, item 9: https://gist.github.com/devdanzin/3198710e3c0128fda5e0a7b4e0768e5f
Linked PRs
- gh-153971
- gh-155923
- gh-155924
- gh-155931
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
subprocess.CalledProcessError.str から始め、None returncode を指定して issue の例を再現してください。失敗する表現のカバレッジを追加し、str(err) が例外を発生させずに単純なメッセージを返すことを確認してください。作業はすでにこの issue に対してリストアップされているため、開始前にリンクされている PRs を確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 30/100