You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dataclass(slots=True) incompatible with __init_subclass__ #91126
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'
Activity
crusaderky commentedon Mar 10, 2022
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.
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'
ericvsmith commentedon Mar 10, 2022
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'
fix: make compatible with python3.10
sobolevn commentedon Aug 23, 2024
I think that we should add this case to the docs. Because there's really nothing we can do to support this case.
Solutions:
slots=True, write manual slots__init_subclass__I will send a PR with the proposed note about that.
pythongh-91126: Docs and tests for slotted dataclasses with `__init_s…
gh-91126: Docs and tests for slotted dataclasses with `__init_subclas…
pythongh-91126: Docs and tests for slotted dataclasses with `__init_s…
pythongh-91126: Docs and tests for slotted dataclasses with `__init_s…
[3.12] gh-91126: Docs and tests for slotted dataclasses with `__init_…
[3.13] gh-91126: Docs and tests for slotted dataclasses with `__init_…