-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Improve dataclass docstring #94686
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
Improve dataclass docstring #94686
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
My guess is that this is too small for NEWS, but I'm happy to add it if necessary. |
Lib/dataclasses.py
Outdated
@@ -1193,19 +1193,19 @@ def _add_slots(cls, is_frozen, weakref_slot): | |||
def dataclass(cls=None, /, *, init=True, repr=True, eq=True, order=False, | |||
unsafe_hash=False, frozen=False, match_args=True, | |||
kw_only=False, slots=False, weakref_slot=False): | |||
"""Returns the same class as was passed in, with dunder methods | |||
added based on the fields defined in the class. | |||
"""Return the same class as was passed in, with dunder methods added |
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.
It's actually no longer true that the same class is returned (in the case of slots=True
). I'm not sure of the exact wording that should be used. Otherwise looks good.
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.
Now that I think about it more, I think we should just drop "Return the same class as was passed in", and say "Add dunder methods based on ...".
Agreed. |
Lib/dataclasses.py
Outdated
assigned to after instance creation. If match_args is true, the | ||
__match_args__ tuple is added. If kw_only is true, then by default | ||
all fields are keyword-only. If slots is true, a __slots__ attribute | ||
is added. |
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.
Here is where it should say that if slots is true, a new class is returned.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
I have made the requested changes; please review again. |
Thanks for making the requested changes! @ericvsmith: please review the changes made to this pull request. |
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.
Thanks!
I will commit once @TomFryers has signed the CLA. edit: Hmm, now it's showing as signed (which it wasn't a minute ago). I'll commit once the tests have passed. |
Thanks @TomFryers for the PR, and @ericvsmith for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, @TomFryers and @ericvsmith, I could not cleanly backport this to |
GH-94716 is a backport of this pull request to the 3.11 branch. |
(cherry picked from commit a10cf2f) Co-authored-by: Tom Fryers <61272761+TomFryers@users.noreply.github.com>
(cherry picked from commit a10cf2f) Co-authored-by: Tom Fryers <61272761+TomFryers@users.noreply.github.com>
This fixes three trivial issues: