]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class...
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 12 Aug 2025 11:16:54 +0000 (04:16 -0700)
committerGitHub <noreply@github.com>
Tue, 12 Aug 2025 11:16:54 +0000 (13:16 +0200)
commit6859b95cfff26c9ef52c5535d2b3662f17ff5b3d
tree427bcbda506ae88cf63417aff3c8da0a7b220856
parent027cacb67ce1b16a96a6a2866299803eff16a4a6
gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (take 2) (GH-137047)

Remove the `__dict__` and `__weakref__` descriptors from the original class when creating a dataclass from it.

An interesting hack, but more localized in scope than gh-135230.

This may be a breaking change if people intentionally keep the original class around
when using `@dataclass(slots=True)`, and then use `__dict__` or `__weakref__` on the
original class.

Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/dataclasses.py
Lib/test/test_dataclasses/__init__.py
Misc/NEWS.d/next/Library/2025-07-20-16-56-55.gh-issue-135228.n_XIao.rst [new file with mode: 0644]
Python/clinic/sysmodule.c.h
Python/sysmodule.c