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

Created on 2020-11-05 15:38 by eric.smith, last changed 2021-01-08 20:44 by uriyyo.

Pull Requests
URL Status Linked Edit
PR 24171 open uriyyo, 2021-01-08 20:40
Messages (5)
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) * 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).
History
Date User Action Args
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