| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
The pure-Python ISO 8601 parser capped the subsecond group at 9 digits
(\d{1,9}), so parse() raised a ParserError on timestamps with 10 or more
fractional-second digits, even though the Rust parser and
datetime.fromisoformat accept them and truncate to microsecond resolution.
Widen the group to \d+; the existing [:6] truncation already converts any
length down to microseconds, so the result is unchanged for inputs that
already parsed.
Fixes python-pendulum#935
| Back | FazBrowse Home | New Git URL |
Fixes #935.
pendulum.parse() raises a ParserError on ISO 8601 timestamps whose fractional-seconds field has more than 9 digits:
This affects only the pure-Python parser (pendulum/parsing/iso8601.py). The Rust extension already drops the extra digits, and datetime.fromisoformat accepts them too, so the behavior was inconsistent depending on whether the compiled extension was installed.
Root cause
The subsecond capture group was bounded to 9 digits:
With 10 or more digits the whole pattern fails to match. The downstream code already truncates to microsecond resolution (subsecond = m.group("subsecond")[:6]), so the 9-digit cap was the only thing rejecting longer inputs.
Fix
Widen the group to \d+. The existing [:6] truncation converts any length down to microseconds, so results are unchanged for inputs that already parsed, and 10-or-more-digit inputs now parse (truncated), matching the Rust parser and the standard library.
Test
Added test_parse_iso8601_subsecond_more_than_nine_digits in tests/parsing/test_parse_iso8601.py. It imports the pure-Python parse_iso8601 directly so it always exercises this code path regardless of whether the compiled extension is installed. It fails before the change (ParserError) and passes after.