Title: 3.14 regression: slot dataclasses classes leak original class · Issue #135228 · python/cpython · GitHub
Open Graph Title: 3.14 regression: slot dataclasses classes leak original class · Issue #135228 · python/cpython
X Title: 3.14 regression: slot dataclasses classes leak original class · Issue #135228 · python/cpython
Description: Bug report Bug description: While trying to test cattrs on 3.14 I ran into this issue. Here's a simple reproducer that passes on 3.13, but doesn't on 3.14. import gc from dataclasses import dataclass @dataclass(slots=True) class B: b: in...
Open Graph Description: Bug report Bug description: While trying to test cattrs on 3.14 I ran into this issue. Here's a simple reproducer that passes on 3.13, but doesn't on 3.14. import gc from dataclasses import datacla...
X Description: Bug report Bug description: While trying to test cattrs on 3.14 I ran into this issue. Here's a simple reproducer that passes on 3.13, but doesn't on 3.14. import gc from dataclasses import...
Opengraph URL: https://github.com/python/cpython/issues/135228
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"3.14 regression: slot dataclasses classes leak original class","articleBody":"# Bug report\n\n### Bug description:\n\nWhile trying to test cattrs on 3.14 I ran into this issue. Here's a simple reproducer that passes on 3.13, but doesn't on 3.14.\n\n```python\nimport gc\nfrom dataclasses import dataclass\n\n\n@dataclass(slots=True)\nclass B:\n b: int\n\n\ngc.collect()\n\nassert [\n o for o in gc.get_objects() if hasattr(o, \"__name__\") and o.__name__ == \"B\"\n] == [B]\n```\n\nOriginally I ran into this issue with slotted _attrs_ classes but the core problem is the same. Since slotness cannot be added to a class, dataclasses and attrs classes create a class copy with slots instead. The old class used to hang around until a GC collection happened (guess there are some reference cycles, but I never investigated thoroughly).\n\nOn 3.14, a full GC collection does not clean up the original class, causing a leak. Apart from leaking, in case of subclassing the original class will remain in the list of the parent `.__subclasses__()`, causing an issue.\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-135230\n* gh-136893\n* gh-136960\n* gh-136966\n* gh-137013\n* gh-137014\n* gh-137047\n* gh-137666\n* gh-144021\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/Tinche","@type":"Person","name":"Tinche"},"datePublished":"2025-06-06T23:15:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":30},"url":"https://github.com/135228/cpython/issues/135228"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:23222788-6c91-8880-adec-4a2f6c98ba2b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9C76:B22A0:2CD23E5:3C11E16:696EF3AD |
| html-safe-nonce | 203e855002b19c06052392aba0e20b7ba6008f818384155cf5e4e9022843d32f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Qzc2OkIyMkEwOjJDRDIzRTU6M0MxMUUxNjo2OTZFRjNBRCIsInZpc2l0b3JfaWQiOiIzMzY0MDkzMDI1Mzg0ODU0NDQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 100ec0226bc6ac9b6655610e4f9620b69cb405fd312c1346bd93ec2d2bb28ffa |
| hovercard-subject-tag | issue:3126086443 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/135228/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e7ec9ca9e132eaab04d422dea6407962d6bc5a0372d4f65cd9766b42bb527cea/python/cpython/issues/135228 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e7ec9ca9e132eaab04d422dea6407962d6bc5a0372d4f65cd9766b42bb527cea/python/cpython/issues/135228 |
| og:image:alt | Bug report Bug description: While trying to test cattrs on 3.14 I ran into this issue. Here's a simple reproducer that passes on 3.13, but doesn't on 3.14. import gc from dataclasses import datacla... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Tinche |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width