mirror of
https://github.com/python/cpython.git
synced 2026-06-28 03:41:13 +00:00
gh-152060: Fix _pydatetime.fromisoformat() raising AssertionError on invalid lengths (#152061)
This commit is contained in:
parent
f7e5cddcbb
commit
ff781d52d4
3 changed files with 6 additions and 1 deletions
|
|
@ -358,7 +358,8 @@ def _find_isoformat_datetime_separator(dtstr):
|
|||
def _parse_isoformat_date(dtstr):
|
||||
# It is assumed that this is an ASCII-only string of lengths 7, 8 or 10,
|
||||
# see the comment on Modules/_datetimemodule.c:_find_isoformat_datetime_separator
|
||||
assert len(dtstr) in (7, 8, 10)
|
||||
if len(dtstr) not in (7, 8, 10):
|
||||
raise ValueError("Invalid isoformat string")
|
||||
year = int(dtstr[0:4])
|
||||
has_sep = dtstr[4] == '-'
|
||||
|
||||
|
|
|
|||
|
|
@ -3757,6 +3757,7 @@ def test_fromisoformat_fails_datetime(self):
|
|||
'2009-04-19T12:30:45+00:00:90', # Time zone field out from range
|
||||
'2009-04-19T12:30:45-00:90:00', # Time zone field out from range
|
||||
'2009-04-19T12:30:45-00:00:90', # Time zone field out from range
|
||||
'2020-2020', # Ambiguous 9-char date portion
|
||||
]
|
||||
|
||||
for bad_str in bad_strs:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
Fix :meth:`datetime.datetime.fromisoformat` raising :exc:`AssertionError`
|
||||
instead of :exc:`ValueError` for some malformed strings in the pure-Python
|
||||
implementation, matching the C implementation.
|
||||
Loading…
Add table
Add a link
Reference in a new issue