mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
gh-127260: Improve error consistency in both fromisoformat
implementations (#130134)
In the Python implementation, "Z" was allowed where only "+" or "-" should be allowed in time zone specifiers. In the C implementation, ":" was allowed as a separator between the whole and fractional portion of times (seconds). These have both been forbidden and the error messages harmonized.
This commit is contained in:
parent
46ac85e4d9
commit
427dd10250
4 changed files with 14 additions and 2 deletions
|
@ -431,7 +431,7 @@ def _parse_hh_mm_ss_ff(tstr):
|
|||
|
||||
if pos < len_str:
|
||||
if tstr[pos] not in '.,':
|
||||
raise ValueError("Invalid microsecond component")
|
||||
raise ValueError("Invalid microsecond separator")
|
||||
else:
|
||||
pos += 1
|
||||
|
||||
|
@ -489,7 +489,7 @@ def _parse_isoformat_time(tstr):
|
|||
# HH:MM:SS len: 8
|
||||
# HH:MM:SS.f+ len: 10+
|
||||
|
||||
if len(tzstr) in (0, 1, 3):
|
||||
if len(tzstr) in (0, 1, 3) or tstr[tz_pos-1] == 'Z':
|
||||
raise ValueError("Malformed time zone string")
|
||||
|
||||
tz_comps = _parse_hh_mm_ss_ff(tzstr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue