mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Raise a ValueError when there is data that was not covered in the format string. Done to match behavior of pre-existing C-based strptime implementations.
This commit is contained in:
parent
a390c6e194
commit
2b6dfec1cc
2 changed files with 7 additions and 0 deletions
|
@ -423,6 +423,9 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
|
|||
found = format_regex.match(data_string)
|
||||
if not found:
|
||||
raise ValueError("time data did not match format")
|
||||
if len(data_string) != found.end():
|
||||
raise ValueError("unconverted data remains: %s" %
|
||||
data_string[found.end():])
|
||||
year = 1900
|
||||
month = day = 1
|
||||
hour = minute = second = 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue