[New-bugs-announce] [issue46970] dataclass(slots=True) incompatible with __init_subclass__

Guido Imperiale report at bugs.python.org
Wed Mar 9 19:14:28 EST 2022

New submission from Guido Imperiale <crusaderky at gmail.com>:

Related to #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):

class B(A, msg="Hello world!"):

  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'

components: Library (Lib)
messages: 414822
nosy: crusaderky
priority: normal
severity: normal
status: open
title: dataclass(slots=True) incompatible with __init_subclass__
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list