Skip to content
Draft
Changes from all commits
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
16 changes: 7 additions & 9 deletions Lib/_strptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,7 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):

for index, arg in enumerate([data_string, format]):
if not isinstance(arg, str):
msg = "strptime() argument {} must be str, not {}"
raise TypeError(msg.format(index, type(arg)))
raise TypeError(f"strptime() argument {index} must be str, not {type(arg)}")

global _TimeRE_cache, _regex_cache
with _cache_lock:
Expand All @@ -547,15 +546,14 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
del err
bad_directive = bad_directive.replace('\\s', '')
if not bad_directive:
raise ValueError("stray %% in format '%s'" % format) from None
raise ValueError(f"stray % in format {format!r}") from None
bad_directive = bad_directive.replace('\\', '', 1)
raise ValueError("'%s' is a bad directive in format '%s'" %
(bad_directive, format)) from None
raise ValueError(
f"{bad_directive!r} is a bad directive in format {format!r}") from None
_regex_cache[format] = format_regex
found = format_regex.match(data_string)
if not found:
raise ValueError("time data %r does not match format %r" %
(data_string, format))
raise ValueError(f"time data {data_string!r} does not match format {format!r}")
if len(data_string) != found.end():
rest = data_string[found.end():]
# Specific check for '%:z' directive
Expand All @@ -565,9 +563,9 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
and rest[0] != ":"
):
raise ValueError(
f"Missing colon in %:z before '{rest}', got '{data_string}'"
f"Missing colon in %:z before {rest!r}, got {data_string!r}"
)
raise ValueError("unconverted data remains: %s" % rest)
raise ValueError(f"unconverted data remains: {rest!r}")

iso_year = year = None
month = day = 1
Expand Down
Loading