Do not add a plus sign to a negative zero float result - #629
Open
andrewstellman wants to merge 1 commit into
Open
andrewstellman wants to merge 1 commit into
andrewstellman wants to merge 1 commit into
Conversation
Float._new adds "+" when the source had an explicit sign and the result is >= 0. -0.0 >= 0 is True, so "a = -1.5" times 0 was written as "a = +-0.0", which tomlkit's own parser rejects. Add the "+" only when str(result) does not already start with "-". Found by Quality Playbook, an AI code-review tool, with Claude; I reviewed the change.
andrewstellman
marked this pull request as ready for review
October 3, 2026 01:50
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.
Summary
Arithmetic on a float written with an explicit sign renders
+-0.0when the result is negative zero, and tomlkit cannot parse that output.Float._new(tomlkit/items.py:879on master) adds+whenself._sign and result >= 0.-0.0 >= 0isTrue, andstr(-0.0)is already"-0.0". This is the line #345 changed for #341, and negative zero is the case that change left open. A signed integer reaches the same line through true division (n = +0, thendoc["n"] /= -1).The fix adds the
+only whenstr(result)does not already start with-. Negative zero is the only value that is>= 0and prints with a leading-, so no other result renders differently.Agent Drafting Metadata