gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible#136893
Merged
JelleZijlstra merged 3 commits intopython:mainpython/cpython:mainfrom Jul 22, 2025
Merged
gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible#136893JelleZijlstra merged 3 commits intopython:mainpython/cpython:mainfrom
JelleZijlstra merged 3 commits intopython:mainpython/cpython:mainfrom
Conversation
…ke the original class collectible An interesting hack, but more localized in scope than python#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.
Contributor
|
Relying on the |
ncoghlan
approved these changes
Jul 22, 2025
Contributor
ncoghlan
left a comment
There was a problem hiding this comment.
While far from ideal, this mitigation feels like a better state to leave things in while we ponder the possibilities for a cleaner solution.
Suggested tweaks inline to make it clearer that it's only del cls.__dict__ that needs the mapping proxy bypass.
Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
JelleZijlstra
commented
Jul 22, 2025
|
Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Jul 22, 2025
…ke the original class collectible (pythonGH-136893) An interesting hack, but more localized in scope than pythonGH-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. (cherry picked from commit 46cbdf9) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
|
GH-136960 is a backport of this pull request to the 3.14 branch. |
JelleZijlstra
added a commit
that referenced
this pull request
Jul 22, 2025
…ake the original class collectible (GH-136893) (#136960) gh-135228: When @DataClass(slots=True) replaces a dataclass, make the original class collectible (GH-136893) 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. (cherry picked from commit 46cbdf9) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 22, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 22, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
JelleZijlstra
added a commit
to JelleZijlstra/cpython
that referenced
this pull request
Jul 22, 2025
…places a dataclass, make the original class collectible (pythonGH-136893) (python#136960)" This reverts commit 6e1b31b. Modifying the `__dict__` is likely to cause crashes
JelleZijlstra
added a commit
to JelleZijlstra/cpython
that referenced
this pull request
Jul 22, 2025
…lass, make the original class collectible (python#136893)" This reverts commit 46cbdf9.
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 23, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
JelleZijlstra
added a commit
to JelleZijlstra/cpython
that referenced
this pull request
Jul 23, 2025
…ke the original class collectible (python#136893) An interesting hack, but more localized in scope than python#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>
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 25, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 25, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 27, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
hynek
added a commit
to python-attrs/attrs
that referenced
this pull request
Jul 27, 2025
Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
github-merge-queue bot
pushed a commit
to python-attrs/attrs
that referenced
this pull request
Jul 28, 2025
* Fix slotted reference cycles on 3.14 Ref python/cpython#136893 & python/cpython#135228 Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com> * Add news fragment * Bump version tag to CMA Co-authored-by: Brandt Bucher <40968415+brandtbucher@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com> * Apply review comment #1446 (comment) * EAFP --------- Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
taegyunkim
pushed a commit
to taegyunkim/cpython
that referenced
this pull request
Aug 4, 2025
…ke the original class collectible (python#136893) An interesting hack, but more localized in scope than python#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>
taegyunkim
pushed a commit
to taegyunkim/cpython
that referenced
this pull request
Aug 4, 2025
…lass, make the original class collectible (python#136893)" (python#137014) This reverts commit 46cbdf9.
Agent-Hellboy
pushed a commit
to Agent-Hellboy/cpython
that referenced
this pull request
Aug 19, 2025
…ke the original class collectible (python#136893) An interesting hack, but more localized in scope than python#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>
Agent-Hellboy
pushed a commit
to Agent-Hellboy/cpython
that referenced
this pull request
Aug 19, 2025
…lass, make the original class collectible (python#136893)" (python#137014) This reverts commit 46cbdf9.
kumaraditya303
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Sep 9, 2025
…ass, make the original class collectible (pythonGH-136893) (python#136960) pythongh-135228: When @DataClass(slots=True) replaces a dataclass, make the original class collectible (pythonGH-136893) An interesting hack, but more localized in scope than pythonGH-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. (cherry picked from commit 46cbdf9) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An interesting hack, but more localized in scope than #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 theoriginal class.