python / python/cpython

Inconsistent dataclass order behavior on Python 3.13+

Open
#137,658 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-dataclasses type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Semantics of dataclasses __eq__ have changed in Python 3.13+, the semantic is now inconsistent with the order=True generated set of dunder methods on the same Python 3.13+ versions.

Related issues:
#128294
#120645

@dataclasses.dataclass(order=True)
class Data:
    a: float

nan = float("nan")

assert not (Data(nan) < Data(nan))
# assert not (Data(nan) <= Data(nan)), "fails on 3.13 even though {<, ==} are both False"
assert not (Data(nan) > Data(nan))
# assert not (Data(nan) >= Data(nan)), "fails on 3.13 even though {>, ==} are both False"
assert (Data(nan) != Data(nan))
assert not (Data(nan) == Data(nan))

Proposed fix PR: #137497

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs
  • gh-137497

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the dataclasses order comparisons in the issue on Python 3.13+, then read related issues #128294 and #120645 and the proposed fix in PR #137497. Done means the generated ordering comparisons have consistent behavior with equality for NaN values, with regression coverage for the reported assertions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.