You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make document inequality consistent for NaN values - #696
Two separately parsed documents containing the same NaN value compare both equal and unequal:
left=tomlkit.parse("value = nan")
right=tomlkit.parse("value = nan")
left==right# Trueleft!=right# True before this change
Container.__eq__ already treats matching NaNs as equal, including those nested in arrays. Add the corresponding inequality method so != follows that existing document comparison policy. Unsupported operands still return NotImplemented, allowing reflected comparisons.
Validation on Windows / CPython 3.12.10: four new cases fail and six controls pass against the original source; all 102 document tests and all 1,234 tests pass with the fix. Ruff lint/format and git diff --check pass. Mypy reports the same 33 baseline diagnostics. A separate Codex agent independently checked the red/green tests, 768 comparison cases, and reflected/subclass comparison controls.
Duplicate Check
I searched the open PRs and found none that already fixes this issue.
Related open PRs: Targeted NaN searches returned literal parsing, rounding, and numeric fallback changes; none changes document inequality.
Agent Drafting Metadata
Agent: OpenAI Codex
Model: Exact model identifier was not exposed to this worker.
Notes: Codex assisted investigation, implementation, tests, and this description. Independent review was performed by another AI agent; no human review is claimed.
Thanks for raising this. Python's ordinary NaN equality is indeed different. This patch follows the policy already implemented by Container.__eq__, which calls _equal_with_nan: two separately parsed value = nan documents currently compare both equal and unequal. It only makes != consistent with that existing == result.
Would you prefer document equality itself to follow Python's NaN semantics instead? That would require changing __eq__ and its existing NaN behavior as well. It would be useful to settle that direction before updating this branch to resolve its current conflict.
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
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
Two separately parsed documents containing the same NaN value compare both equal and unequal:
Container.__eq__already treats matching NaNs as equal, including those nested in arrays. Add the corresponding inequality method so!=follows that existing document comparison policy. Unsupported operands still returnNotImplemented, allowing reflected comparisons.Validation on Windows / CPython 3.12.10: four new cases fail and six controls pass against the original source; all 102 document tests and all 1,234 tests pass with the fix. Ruff lint/format and
git diff --checkpass. Mypy reports the same 33 baseline diagnostics. A separate Codex agent independently checked the red/green tests, 768 comparison cases, and reflected/subclass comparison controls.Duplicate Check
Agent Drafting Metadata