GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — dataclass(slots=True) incompatible with __init_subclass__ · Issue #91126 · python/cpython

dataclass(slots=True) incompatible with __init_subclass__ #91126

New issue
Copy link
New issue
Copy link
Closed
Closed
dataclass(slots=True) incompatible with __init_subclass__#91126
Copy link
Assignees
ericvsmithsobolevn
Labels
3.10 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

crusaderky
mannequin
opened on Mar 10, 2022
Issue body actions
BPO 46970
Nosy @ericvsmith, @crusaderky

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 = None
created_at = <Date 2022-03-10.00:14:28.417>
labels = ['type-bug', 'library', '3.10']
title = 'dataclass(slots=True) incompatible with __init_subclass__'
updated_at = <Date 2022-03-10.00:28:03.767>
user = 'https://github.com/crusaderky'

bugs.python.org fields:

activity = <Date 2022-03-10.00:28:03.767>
actor = 'eric.smith'
assignee = 'eric.smith'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-03-10.00:14:28.417>
creator = 'crusaderky'
dependencies = []
files = []
hgrepos = []
issue_num = 46970
keywords = []
message_count = 2.0
messages = ['414822', '414823']
nosy_count = 2.0
nosy_names = ['eric.smith', 'crusaderky']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue46970'
versions = ['Python 3.10']

Linked PRs

  • gh-91126: Docs and tests for slotted dataclasses with __init_subclass__ #123342
  • [3.13] gh-91126: Docs and tests for slotted dataclasses with __init_subclass__ (GH-123342) #123568
  • [3.12] gh-91126: Docs and tests for slotted dataclasses with __init_subclass__ (GH-123342) #123569

Activity

  1. crusaderky commented on Mar 10, 2022

    @crusaderky
    crusaderkymannequin
    on Mar 10, 2022
    MannequinAuthor
    More actions

    Related to bpo-46382
    A class decorated with dataclass(slots=True) can't pass any parameters to the __init_subclass__ method of its parent class.

    from dataclasses import dataclass
    
    class A:
        __slots__ = ()
        def __init_subclass__(cls, msg):
            print(msg)
    
    @dataclass(slots=True)
    class B(A, msg="Hello world!"):
        pass

    File "lib/python3.10/dataclasses.py", line 1145, in _add_slots
    cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)
    TypeError: A.__init_subclass__() missing 1 required positional argument: 'msg'

  2. crusaderky
    added
    3.10 (EOL)end of lifeend of life
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Mar 10, 2022
  3. ericvsmith commented on Mar 10, 2022

    @ericvsmith
    ericvsmith
    on Mar 10, 2022
    Member
    More actions

    This appears to be due to dataclasses needing to create a new class in order to set __slots__. I'll look at it, but I doubt there's anything that can be done.

    attrs has the same issue:
    File "xxxxx/.local/lib/python3.8/site-packages/attr/make.py", line 889, in _create_slots_class
    cls = type(self._cls)(self._cls.__name
    _, self._cls.__bases__, cd)
    TypeError: __init_subclass__() missing 1 required positional argument: 'msg'

  4. ericvsmith
    self-assigned this
    on Mar 10, 2022
  5. ericvsmith
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    and removed
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Mar 10, 2022
  6. ericvsmith
    self-assigned this
    on Mar 10, 2022
  7. ericvsmith
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    and removed
    type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
    on Mar 10, 2022
  8. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  9. andreabak
    added a commit that references this issue on Aug 27, 2023

    fix: make compatible with python3.10

    fcb59c9
  10. picnixz
    added
    topic-dataclasses
    on Aug 16, 2024
  11. sobolevn commented on Aug 23, 2024

    @sobolevn
    sobolevn
    on Aug 23, 2024
    Member
    More actions

    I think that we should add this case to the docs. Because there's really nothing we can do to support this case.

    Solutions:

    1. Don't do that
    2. Don't use slots=True, write manual slots
    3. Have defaults for __init_subclass__

    I will send a PR with the proposed note about that.

  12. sobolevn
    self-assigned this
    on Aug 23, 2024
  13. sobolevn
    added 2 commits that reference this issue on Aug 26, 2024

    pythongh-91126: Docs and tests for slotted dataclasses with `__init_s…

    0939d82

    gh-91126: Docs and tests for slotted dataclasses with `__init_subclas…

    75e7282
  14. miss-islington
    added 2 commits that reference this issue on Sep 1, 2024

    pythongh-91126: Docs and tests for slotted dataclasses with `__init_s…

    9265957

    pythongh-91126: Docs and tests for slotted dataclasses with `__init_s…

    33a044b
  15. sobolevn
    added 2 commits that reference this issue on Sep 1, 2024

    [3.12] gh-91126: Docs and tests for slotted dataclasses with `__init_…

    12db938

    [3.13] gh-91126: Docs and tests for slotted dataclasses with `__init_…

    cfdf376
  16. sobolevn
    closed this as completedon Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ericvsmith
    ericvsmith
  • @sobolevn
    sobolevn

Labels

3.10 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.