You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strptime: use %r in error messages, not %s #141540
$ 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 _strptimeraiseValueError("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:
@alexwlchan - Can you find other places with a similar issue? Can you submit a fix for multiple places? The fix is trivial so it should be easy for you to submit a PR (make sure to reference this one).
Activity
gvanrossum commentedon Nov 14, 2025
@alexwlchan - Can you find other places with a similar issue? Can you submit a fix for multiple places? The fix is trivial so it should be easy for you to submit a PR (make sure to reference this one).
use %r instead of %s in error messages python#141540
pythongh-141540: Quote the %:z error message with !r as well
pythongh-141540: Quote the colon error message with !r as well
gh-141540: Quote unconverted data in `strptime` error messages (#157832)