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:
donBarbos 2025-02-18 19:49:28 +04:00 committed by GitHub
parent 46ac85e4d9
commit 427dd10250
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 2 deletions

View file

@ -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)