GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible by JelleZijlstra · Pull Request #136893 · python/cpython

Conversation

@JelleZijlstra

@JelleZijlstra JelleZijlstra commented Jul 20, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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 the
original class.

  • Issue: 3.14 regression: slot dataclasses classes leak original class #135228

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@JelleZijlstra
pythongh-135228: When @DataClass(slots=True) replaces a dataclass, ma…
027f629
…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.
@JelleZijlstra
JelleZijlstra requested a review from ericvsmith as a code owner July 20, 2025 23:59
@bedevere-app bedevere-app Bot added the awaiting core review label Jul 20, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Jul 20, 2025
3.14 regression: slot dataclasses classes leak original class #135228
Closed
@ncoghlan

ncoghlan commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

Relying on the __ror__ mapping proxy bypass is unpleasant, but this seems like the simplest near-term workaround, since even though del cls.__weakref__ works without any tricks, del cls.__dict__ fails due to the way that descriptor is defined.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ncoghlan
ncoghlan approved these changes Jul 22, 2025
View reviewed changes

@ncoghlan ncoghlan left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/dataclasses.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/dataclasses.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Jul 22, 2025
@JelleZijlstra @ncoghlan
Apply suggestions from code review
e0d61f7
Co-authored-by: Alyssa Coghlan <[email protected]>
@JelleZijlstra JelleZijlstra added the needs backport to 3.14 bugs and security fixes label Jul 22, 2025
JelleZijlstra
JelleZijlstra commented Jul 22, 2025
View reviewed changes
Comment thread Lib/dataclasses.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra
Update Lib/dataclasses.py
d545002
@JelleZijlstra
JelleZijlstra merged commit 46cbdf9 into python:main Jul 22, 2025
@miss-islington-app

miss-islington-app Bot commented Jul 22, 2025

Copy link
Copy Markdown

Thanks @JelleZijlstra for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 22, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 22, 2025
@JelleZijlstra @ncoghlan @miss-islington
pythongh-135228: When @DataClass(slots=True) replaces a dataclass, ma…
c6fde2d
…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 <[email protected]>
Co-authored-by: Alyssa Coghlan <[email protected]>
@bedevere-app

bedevere-app Bot commented Jul 22, 2025

Copy link
Copy Markdown

GH-136960 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 22, 2025
@JelleZijlstra
JelleZijlstra deleted the hackweakref branch July 22, 2025 04:51
JelleZijlstra added a commit that referenced this pull request Jul 22, 2025
@miss-islington @JelleZijlstra @ncoghlan
[3.14] gh-135228: When @DataClass(slots=True) replaces a dataclass, m…
6e1b31b
…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 <[email protected]>
Co-authored-by: Alyssa Coghlan <[email protected]>
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 22, 2025
@hynek
Fix slotted reference cycles on 3.14
cb7dd8f
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra
<[email protected]>
@hynek hynek mentioned this pull request Jul 22, 2025
Fix slotted reference cycles on 3.14 python-attrs/attrs#1446
Merged
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 22, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14
d32355b
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>
@JelleZijlstra JelleZijlstra mentioned this pull request Jul 22, 2025
[3.14] Revert "[3.14] gh-135228: When @dataclass(slots=True) replaces… #137013
Merged
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request Jul 22, 2025
@JelleZijlstra
[3.14] Revert "[3.14] pythongh-135228: When @DataClass(slots=True) re…
58b43b2
…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
@JelleZijlstra
Revert "pythongh-135228: When @DataClass(slots=True) replaces a datac…
7a083f3
…lass, make the original class collectible (python#136893)"

This reverts commit 46cbdf9.
JelleZijlstra added a commit that referenced this pull request Jul 23, 2025
@JelleZijlstra
Revert "gh-135228: When @DataClass(slots=True) replaces a dataclass, …
6a285f9
…make the original class collectible (#136893)" (#137014)

This reverts commit 46cbdf9.
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 23, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14
6bb75f8
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this pull request Jul 23, 2025
@JelleZijlstra @ncoghlan
pythongh-135228: When @DataClass(slots=True) replaces a dataclass, ma…
916ce1b
…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 <[email protected]>
@JelleZijlstra JelleZijlstra mentioned this pull request Jul 23, 2025
gh-135228: When @dataclass(slots=True) replaces a dataclass, make the original class collectible (take 2) #137047
Merged
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 25, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14
3ae1bff
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 25, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14
7dd3806
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 27, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14
f4ad208
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>
hynek added a commit to python-attrs/attrs that referenced this pull request Jul 27, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14
ea6a62d
Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>
github-merge-queue Bot pushed a commit to python-attrs/attrs that referenced this pull request Jul 28, 2025
@hynek @JelleZijlstra
Fix slotted reference cycles on 3.14 (#1446)
000c563
* Fix slotted reference cycles on 3.14

Ref python/cpython#136893 &
python/cpython#135228

Co-authored-by: Jelle Zijlstra <[email protected]>

* Add news fragment

* Bump version tag to CMA

Co-authored-by: Brandt Bucher
<[email protected]>
Co-authored-by: Jelle Zijlstra
<[email protected]>

* Apply review comment

#1446 (comment)

* EAFP

---------

Co-authored-by: Jelle Zijlstra <[email protected]>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@JelleZijlstra @ncoghlan @taegyunkim
pythongh-135228: When @DataClass(slots=True) replaces a dataclass, ma…
5f4992d
…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 <[email protected]>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@JelleZijlstra @taegyunkim
Revert "pythongh-135228: When @DataClass(slots=True) replaces a datac…
9df2cfe
…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
@JelleZijlstra @ncoghlan @Agent-Hellboy
pythongh-135228: When @DataClass(slots=True) replaces a dataclass, ma…
fd504e9
…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 <[email protected]>
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
@JelleZijlstra @Agent-Hellboy
Revert "pythongh-135228: When @DataClass(slots=True) replaces a datac…
b41a7bd
…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
@miss-islington @JelleZijlstra
@ncoghlan @kumaraditya303
[3.14] pythongh-135228: When @DataClass(slots=True) replaces a datacl…
5008e85
…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 <[email protected]>
Co-authored-by: Alyssa Coghlan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ncoghlan ncoghlan ncoghlan approved these changes
@ericvsmith ericvsmith Awaiting requested review from ericvsmith ericvsmith is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@JelleZijlstra @ncoghlan
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.