Skip to content
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

Add ability to set __slots__ in dataclasses #86435

Closed
ericvsmith opened this issue Nov 5, 2020 · 7 comments
Closed

Add ability to set __slots__ in dataclasses #86435

ericvsmith opened this issue Nov 5, 2020 · 7 comments
Assignees
Labels
3.10 stdlib type-bug

Comments

@ericvsmith
Copy link
Member

@ericvsmith ericvsmith commented Nov 5, 2020

BPO 42269
Nosy @ericvsmith, @jstasiak, @MojoVampire, @pbryan, @uriyyo, @Xtrem532, @lcy0321
PRs
  • #24171
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ericvsmith'
    closed_at = <Date 2021-05-01.02:15:08.358>
    created_at = <Date 2020-11-05.15:38:14.065>
    labels = ['type-bug', 'library', '3.10']
    title = 'Add ability to set __slots__ in dataclasses'
    updated_at = <Date 2021-05-01.02:15:08.358>
    user = 'https://github.com/ericvsmith'

    bugs.python.org fields:

    activity = <Date 2021-05-01.02:15:08.358>
    actor = 'eric.smith'
    assignee = 'eric.smith'
    closed = True
    closed_date = <Date 2021-05-01.02:15:08.358>
    closer = 'eric.smith'
    components = ['Library (Lib)']
    creation = <Date 2020-11-05.15:38:14.065>
    creator = 'eric.smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42269
    keywords = ['patch']
    message_count = 7.0
    messages = ['380416', '380734', '380740', '380759', '384690', '392563', '392564']
    nosy_count = 7.0
    nosy_names = ['eric.smith', 'jstasiak', 'josh.r', 'pbryan', 'uriyyo', 'Xtrem532', 'lcy0321']
    pr_nums = ['24171']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42269'
    versions = ['Python 3.10']

    @ericvsmith
    Copy link
    Member Author

    @ericvsmith ericvsmith commented Nov 5, 2020

    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.

    @ericvsmith ericvsmith added the 3.10 label Nov 5, 2020
    @ericvsmith ericvsmith self-assigned this Nov 5, 2020
    @ericvsmith ericvsmith added stdlib type-bug 3.10 labels Nov 5, 2020
    @ericvsmith ericvsmith self-assigned this Nov 5, 2020
    @ericvsmith ericvsmith added stdlib type-bug labels Nov 5, 2020
    @MojoVampire
    Copy link
    Mannequin

    @MojoVampire MojoVampire mannequin commented Nov 11, 2020

    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?

    @ericvsmith
    Copy link
    Member Author

    @ericvsmith ericvsmith commented Nov 11, 2020

    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.

    @jstasiak
    Copy link
    Mannequin

    @jstasiak jstasiak mannequin commented Nov 11, 2020

    As a moderately-heavy dataclass user I support this. :)

    @uriyyo
    Copy link
    Member

    @uriyyo uriyyo commented Jan 8, 2021

    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).

    @ericvsmith
    Copy link
    Member Author

    @ericvsmith ericvsmith commented May 1, 2021

    New changeset c241991 by Yurii Karabas in branch 'master':
    bpo-42269: Add slots parameter to dataclass decorator (GH-24171)
    c241991

    @ericvsmith
    Copy link
    Member Author

    @ericvsmith ericvsmith commented May 1, 2021

    Thanks for all of your work, Yurii.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 stdlib type-bug
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants