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
Inconsistent dataclass order behavior on Python 3.13+ #137658
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.
@dataclasses.dataclass(order=True)classData:
a: floatnan=float("nan")
assertnot (Data(nan) <Data(nan))
# assert not (Data(nan) <= Data(nan)), "fails on 3.13 even though {<, ==} are both False"assertnot (Data(nan) >Data(nan))
# assert not (Data(nan) >= Data(nan)), "fails on 3.13 even though {>, ==} are both False"assert (Data(nan) !=Data(nan))
assertnot (Data(nan) ==Data(nan))
Can you please show code where the values of comparisons change as a result of this PR? I presume they're all NaN related, or values with equally wacky comparison methods. But I'd like any actual change in semantics to be noted.
@ericvsmith Yes related to weird NaN-like objects, in the example code above the commented out lines will fail. Added similar tests to the PR that pass for this scenario, but generally the PR writes the order methods in a way more consistent with the current accepted semantics of __eq__ after it was optimized.
Ever since semantics of __eq__ changed in 3.13+ the order methods have still been using the direct tuple semantics causing a slight misalignment shown in this issue.
Activity
ericvsmith commentedon Sep 19, 2025
Can you please show code where the values of comparisons change as a result of this PR? I presume they're all NaN related, or values with equally wacky comparison methods. But I'd like any actual change in semantics to be noted.
gesslerpd commentedon Sep 24, 2025
@ericvsmith Yes related to weird NaN-like objects, in the example code above the commented out lines will fail. Added similar tests to the PR that pass for this scenario, but generally the PR writes the order methods in a way more consistent with the current accepted semantics of
__eq__after it was optimized.Ever since semantics of
__eq__changed in 3.13+ the order methods have still been using the direct tuple semantics causing a slight misalignment shown in this issue.