Accept ISO 8601 fractional seconds with more than 9 digits#976
Open
vineethsaivs wants to merge 1 commit into
Open
Accept ISO 8601 fractional seconds with more than 9 digits#976vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #935.
pendulum.parse()raises aParserErroron 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, anddatetime.fromisoformataccepts 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_digitsintests/parsing/test_parse_iso8601.py. It imports the pure-Pythonparse_iso8601directly so it always exercises this code path regardless of whether the compiled extension is installed. It fails before the change (ParserError) and passes after.