Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use repr in fromisoformat error message
This reverses commit 67b74a98b2 per Serhiy Storchaka's suggestion:

     I suggested to use %R in the error message because including the raw
     string can be confusing in the case of empty string, or string
     containing trailing whitespaces, invisible or unprintable characters.

We agree that it is better to change both the C and pure Python versions
to use repr.
  • Loading branch information
pganssle committed Oct 21, 2018
commit 6d6f3d0a55aa5a57a8cac5b39b4409fad8a5298e
8 changes: 4 additions & 4 deletions Lib/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def fromisoformat(cls, date_string):
assert len(date_string) == 10
return cls(*_parse_isoformat_date(date_string))
except Exception:
raise ValueError('Invalid isoformat string: %s' % date_string)
raise ValueError(f'Invalid isoformat string: {date_string!r}')


# Conversions to string
Expand Down Expand Up @@ -1369,7 +1369,7 @@ def fromisoformat(cls, time_string):
try:
return cls(*_parse_isoformat_time(time_string))
except Exception:
raise ValueError('Invalid isoformat string: %s' % time_string)
raise ValueError(f'Invalid isoformat string: {time_string!r}')


def strftime(self, fmt):
Expand Down Expand Up @@ -1646,13 +1646,13 @@ def fromisoformat(cls, date_string):
try:
date_components = _parse_isoformat_date(dstr)
except ValueError:
raise ValueError('Invalid isoformat string: %s' % date_string)
raise ValueError(f'Invalid isoformat string: {date_string!r}')

if tstr:
try:
time_components = _parse_isoformat_time(tstr)
except ValueError:
raise ValueError('Invalid isoformat string: %s' % date_string)
raise ValueError(f'Invalid isoformat string: {date_string!r}')
else:
time_components = [0, 0, 0, 0, None]

Expand Down