Repository navigation
Reject non-finite numbers in JSON CLI output - #155
Merged
Merged
Conversation
Pass allow_nan=False for --as-json and report encoding errors without emitting invalid JSON. Keep default JSON5 non-finite output supported. Prepared with AI assistance; contributor review is required before upload.
dpranke
approved these changes
Nov 2, 2026
dpranke
left a comment
Owner
There was a problem hiding this comment.
I think this is fine and probably an improvement over the code as it stands.
However, please see my comment on the linked bug, as this isn't actually the
way I want things to work; dump should just take an actual as_json flag.
And, even then, I don't want to guarantee that the output will exactly match
whatever JSON does, as long as it is producing a legal JSON document that
will evaluate to the same value.
But, all that's really a separate patch than this PR, so I'll land this for now.
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 #151.
--as-jsoncurrently emits NaN and Infinity tokens despite promising JSON output. Passallow_nan=Falsein that mode, report the encoder's ValueError to stderr and exit with status 1 before printing output. Default JSON5 output retains non-finite support. Update the CLI help accordingly.The regression runs through both the hosted test helper and a real CLI subprocess. It fails against the original source. Existing encoder tests already cover the individual non-finite values.
All 97 tests pass on Windows/Python 3.14 and Ubuntu/Python 3.10; Windows line coverage is 100%. Ruff, pylint, mypy, formatting and package builds pass. Other supported interpreters and hosted CI have not been verified locally.
Prepared with AI assistance. The contributor confirmed reviewing and vetting this commit before upload.