-
-
Notifications
You must be signed in to change notification settings - Fork 32k
dataclass(slots=True) incompatible with __init_subclass__ #91126
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
Comments
Related to bpo-46382 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 |
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: |
The main change is to remove slots=True from dataclasses decorators, due to CPython bug: python/cpython#91126
I think that we should add this case to the docs. Because there's really nothing we can do to support this case. Solutions:
I will send a PR with the proposed note about that. |
…ubclass__` (pythonGH-123342) (cherry picked from commit 75e7282) Co-authored-by: sobolevn <mail@sobolevn.me>
…ubclass__` (pythonGH-123342) (cherry picked from commit 75e7282) Co-authored-by: sobolevn <mail@sobolevn.me>
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:
bugs.python.org fields:
Linked PRs
__init_subclass__
#123342__init_subclass__
(GH-123342) #123568__init_subclass__
(GH-123342) #123569The text was updated successfully, but these errors were encountered: