-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-138991: Update dataclass documentation for new eq behavior in Python 3.13 and add tests #139007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
1b4a856
08b07a2
3692677
262f785
ada26a9
5712279
822bbaa
03445c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,9 +103,19 @@ Module contents | |
ignored. | ||
|
||
- *eq*: If true (the default), an :meth:`~object.__eq__` method will be | ||
generated. This method compares the class as if it were a tuple | ||
of its fields, in order. Both instances in the comparison must | ||
be of the identical type. | ||
generated. | ||
|
||
.. versionchanged:: 3.13 | ||
The generated ``__eq__`` method now compares each field individually | ||
(for example, ``self.a == other.a and self.b == other.b``), rather than | ||
comparing tuples of fields as in previous versions. | ||
|
||
This method compares the class by comparing each field in order. Both | ||
instances in the comparison must be of the identical type. | ||
|
||
In Python 3.12 and earlier, the comparison was performed by creating | ||
tuples of the fields and comparing them (for example, | ||
``(self.a, self.b) == (other.a, other.b)``). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how the formatting would work out, but I think the note about 3.12 should be part of the versionchanged note. Also, might it be worth mentioning why this matters? It would matter for any value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For formatting, @StanFromIreland suggested wrapping lines to 79 characters. For the other changes you suggested, I’d like to wait until they are confirmed before updating. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By "formatting", I meant possibly multiple paragraphs in a versionadded block. I don't know if that's possible (or desirable). |
||
|
||
If the class already defines :meth:`!__eq__`, this parameter is | ||
ignored. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this sentence should come before the versionchanged note. It's a description of how the method works, which is more important than how it changed over time.