Raise DurationParsingException on decimal overflow instead of leaking decimal.Overflow - #29
Open
cognis-digital wants to merge 1 commit into
Conversation
…aking decimal.Overflow
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.
parse_duration()promises to raiseDurationParsingExceptionfor any malformed input,but a value whose magnitude overflows the
decimalcontext escapes that contract with araw
decimal.Overflow:is_number()accepts scientific-notatione/E, so1E1000000is accepted as a numerictoken.
Decimal("1E1000000")constructs without issue, but the subsequentsign * Decimal(...)runs under the default decimal context (Emax 999999) and signalsOverflow. Both arithmetic sites inparser/parsing.pyonly caughtInvalidOperation, sothe overflow bypassed the library's exception hierarchy — a problem for callers such as
jsonschema'sdurationformat check that catch onlyDurationParsingException.This broadens the handler at both sites from
decimal.InvalidOperationto its base classdecimal.DecimalException. SinceInvalidOperationis a subclass ofDecimalException,all previously handled inputs behave identically; overflow (and any other decimal signal)
is now reported as
UnparseableValue, consistent with other unparseable numeric values.Adds regression tests for both the date (
P1E1000000D) and time (PT1E1000000S) paths.Full test suite passes (378 passed).