Inconsistent dataclass order behavior on Python 3.13+
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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