Repository navigation
Conversation
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 #381.
Problem and change
Python's
json.loads()acceptsInfinity,-Infinity, andNaNby default. JMESPath classifies these Python floats as numbers, butmath.floor()/math.ceil()cannot convert them to integers and raise bareOverflowError/ValueErrorduringsearch().Preserve non-finite float arguments unchanged in these two functions, one of the behaviors suggested in the issue. Finite floats still use the standard-library rounding behavior. The check is restricted to floats so arbitrary-size Python integers (e.g.
10 ** 400) do not undergo a float conversion and continue to work. Existing argument type validation is unchanged.Tests
python -m pytest tests/test_functions.py -q: 1 failed, 7 passed, with the new regression failing onfloor(Infinity)withOverflowError.python -m pytest tests -q: 994 passed, 1 skipped, with 14 existing deprecated-string-literal warnings (Python 3.13.5).E9,F63,F7,F82) andgit diff --checkpass.Tests ran in an independent venv with an empty environment, automatic third-party pytest plugins disabled, and networking disabled through a network namespace. No production services were changed.
Scope / disclosure
This only defines behavior for Python's non-finite float extension; it does not change the JSON/JMESPath numeric specification,
to_number(), or other numeric functions. There has not yet been maintainer confirmation of which proposed behavior is preferred; preserving non-finite values is the deliberately narrow choice here, and feedback is welcome.Prepared with AI assistance. No independent human code review is claimed.