Skip to content

Make document inequality consistent for NaN values - #696

Open
Sskift wants to merge 1 commit into
python-poetry:masterfrom
Sskift:fix/container-nan-inequality
Open

Sskift wants to merge 1 commit into
python-poetry:masterfrom
Sskift:fix/container-nan-inequality

Conversation

@Sskift

@Sskift Sskift commented Nov 2, 2026

Copy link
Copy Markdown

Summary

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  # True
left != 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.

@dimbleby

dimbleby commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

surely this is fixing in the wrong direction, making tomlkit behaviour the exact opposite of regular python comparison for NaN values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants