Skip to content

Commit 6d6f3d0

Browse files
committed
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.
1 parent 76b274d commit 6d6f3d0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Lib/datetime.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ def fromisoformat(cls, date_string):
857857
assert len(date_string) == 10
858858
return cls(*_parse_isoformat_date(date_string))
859859
except Exception:
860-
raise ValueError('Invalid isoformat string: %s' % date_string)
860+
raise ValueError(f'Invalid isoformat string: {date_string!r}')
861861

862862

863863
# Conversions to string
@@ -1369,7 +1369,7 @@ def fromisoformat(cls, time_string):
13691369
try:
13701370
return cls(*_parse_isoformat_time(time_string))
13711371
except Exception:
1372-
raise ValueError('Invalid isoformat string: %s' % time_string)
1372+
raise ValueError(f'Invalid isoformat string: {time_string!r}')
13731373

13741374

13751375
def strftime(self, fmt):
@@ -1646,13 +1646,13 @@ def fromisoformat(cls, date_string):
16461646
try:
16471647
date_components = _parse_isoformat_date(dstr)
16481648
except ValueError:
1649-
raise ValueError('Invalid isoformat string: %s' % date_string)
1649+
raise ValueError(f'Invalid isoformat string: {date_string!r}')
16501650

16511651
if tstr:
16521652
try:
16531653
time_components = _parse_isoformat_time(tstr)
16541654
except ValueError:
1655-
raise ValueError('Invalid isoformat string: %s' % date_string)
1655+
raise ValueError(f'Invalid isoformat string: {date_string!r}')
16561656
else:
16571657
time_components = [0, 0, 0, 0, None]
16581658

0 commit comments

Comments
 (0)