Raise Invalid for Infinity/NaN input to Number validator - #542
Merged
alecthomas merged 1 commit intoJul 11, 2026
Conversation
SAY-5
force-pushed
the
fix-number-infinity-nan-invalid
branch
2 times, most recently
from
July 2, 2026 08:42
67636bc to
1c39734
Compare
Owner
|
This has conflicts now that #539 is merged. |
SAY-5
force-pushed
the
fix-number-infinity-nan-invalid
branch
from
July 10, 2026 19:49
1c39734 to
e3470ef
Compare
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
SAY-5
force-pushed
the
fix-number-infinity-nan-invalid
branch
from
July 10, 2026 19:55
e3470ef to
8bc6fa2
Compare
Contributor
Author
|
Rebased onto master. #539 changed the |
alecthomas
approved these changes
Jul 10, 2026
Owner
|
Thanks! |
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 #541.
Number(precision, scale)documents:raises Invalid:, butNumber(precision=6, scale=2)("Infinity")(also"NaN"/"-Infinity") leaks a rawTypeError("infinity and NaN have no precision").Decimal(number)succeeds for these, thenas_tuple().exponentis a string rather than an int, so_get_precision_scalefell into theelsebranch that raisedTypeError. The commented-out line there already showed the intended behaviour.The
elsenow raisesInvalidwith the same message theInvalidOperationsibling uses, so a non-finite value is rejected like any other unusable number. Addedtest_number_validation_with_infinity_and_nanmirroringtest_number_validation_with_string; it fails before the change and passes after. Full suite: 168 passed, flake8 clean.This is separate from #539, which handles
None/dict/bytesbefore theDecimal()call and explicitly leaves this non-finite path alone.