strptime: use %r in error messages, not %s
オープン
まだ誰も着手していません。
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
Consider the following example, say I'm parsing a date string read from an external source, and I forgot to call .strip():
from datetime import datetime
datetime.strptime("2001-02-03\n", "%Y-%m-%d")
The output is a little confusing:
$ python3 strptime_example.py
Traceback (most recent call last):
File "strptime_example.py", line 3, in <module>
datetime.strptime("2025-11-14\n", "%Y-%m-%d")
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_strptime.py", line 789, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/_strptime.py", line 558, in _strptime
raise ValueError("unconverted data remains: %s" %
data_string[found.end():])
ValueError: unconverted data remains:
The error message is using %s, when using %r would give a more unambiguous description of the extra data – similar with strings quoted manually using ' in the error message just above:
CPython versions tested on:
3.13
Operating systems tested on:
macOS
Linked PRs
- gh-141541
- gh-141712
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/_strptime.py の、報告で示されている行にある未変換データのエラー付近から始め、末尾に改行を含む例を再現します。残りのデータが、近くにあるエラーメッセージと一貫した repr 形式のフォーマットで曖昧さなく示されれば、作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100