This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add ability to set __slots__ in dataclasses
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Xtrem532, eric.smith, josh.r, jstasiak, lcy0321, pbryan, uriyyo
Priority: normal Keywords: patch

Created on 2020-11-05 15:38 by eric.smith, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24171 merged uriyyo, 2021-01-08 20:40
Messages (7)
msg380416 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-11-05 15:38
I resisted adding the ability to set __slots__ in the first version of dataclasses, since it requires that instead of modifying an existing class, an entirely new class is returned.

But I think this feature would be useful enough that I'm now willing to add it. I have the code ready, I just need to work on tests and documentation.
msg380734 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2020-11-11 06:32
Is the plan to allow an argument to auto-generate __slots__, or would this require repeating the names once in __slots__, and once for annotations and the like?
msg380740 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-11-11 07:47
It would figure it out automatically. See https://github.com/ericvsmith/dataclasses/blob/master/dataclass_tools.py for a decorator that already does this.

I'll have a PR ready soon, I hope.
msg380759 - (view) Author: Jakub Stasiak (jstasiak) * Date: 2020-11-11 13:49
As a moderately-heavy dataclass user I support this. :)
msg384690 - (view) Author: Yurii Karabas (uriyyo) * (Python triager) Date: 2021-01-08 20:44
Hi Eric, I tried to help you with this feature and have opened a PR. I thought that you are too busy to implement this feature, so that's why I decided to help you (It almost two months since your last message in this thread).
msg392563 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-05-01 02:14
New changeset c24199184bea0c851c1a7296ae54aaf18ee56752 by Yurii Karabas in branch 'master':
bpo-42269: Add slots parameter to dataclass decorator (GH-24171)
https://github.com/python/cpython/commit/c24199184bea0c851c1a7296ae54aaf18ee56752
msg392564 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-05-01 02:15
Thanks for all of your work, Yurii.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86435
2021-05-01 02:15:08eric.smithsetstatus: open -> closed
resolution: fixed
messages: + msg392564

stage: patch review -> resolved
2021-05-01 02:14:36eric.smithsetmessages: + msg392563
2021-02-08 02:36:58pbryansetnosy: + pbryan
2021-01-08 20:44:20uriyyosetmessages: + msg384690
2021-01-08 20:40:14uriyyosetkeywords: + patch
nosy: + uriyyo

pull_requests: + pull_request22998
stage: patch review
2021-01-08 15:55:48lcy0321setnosy: + lcy0321
2020-11-11 16:10:50Xtrem532setnosy: + Xtrem532
2020-11-11 13:49:40jstasiaksetmessages: + msg380759
2020-11-11 07:47:56eric.smithsetmessages: + msg380740
2020-11-11 06:32:38josh.rsetmessages: + msg380734
2020-11-11 06:31:16josh.rsetnosy: + josh.r
2020-11-05 16:56:52jstasiaksetnosy: + jstasiak
2020-11-05 15:38:14eric.smithcreate