Title: dataclass(slots=True) fails if method has an empty `__class__` cell · Issue #148947 · python/cpython · GitHub
Open Graph Title: dataclass(slots=True) fails if method has an empty `__class__` cell · Issue #148947 · python/cpython
X Title: dataclass(slots=True) fails if method has an empty `__class__` cell · Issue #148947 · python/cpython
Description: Bug report Bug description: On Python 3.14, this code: def maker(): if False: __class__ = 42 def method(self): return __class__ return method from dataclasses import dataclass @dataclass(slots=True) class X: a: int meth = maker() Fails w...
Open Graph Description: Bug report Bug description: On Python 3.14, this code: def maker(): if False: __class__ = 42 def method(self): return __class__ return method from dataclasses import dataclass @dataclass(slots=True...
X Description: Bug report Bug description: On Python 3.14, this code: def maker(): if False: __class__ = 42 def method(self): return __class__ return method from dataclasses import dataclass @dataclass(slots=True...
Opengraph URL: https://github.com/python/cpython/issues/148947
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"dataclass(slots=True) fails if method has an empty `__class__` cell","articleBody":"# Bug report\n\n### Bug description:\n\nOn Python 3.14, this code:\n\n```python\ndef maker():\n if False:\n __class__ = 42\n\n def method(self):\n return __class__\n return method\n\nfrom dataclasses import dataclass\n\n@dataclass(slots=True)\nclass X:\n a: int\n\n meth = maker()\n```\n\nFails with `ValueError: Cell is empty`, because some dataclasses machinery for updating the `__class__` cell doesn't reckon with the possibility that the cell may be empty.\n\n### CPython versions tested on:\n\n3.14, CPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-148948\n* gh-148995\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2026-04-24T04:19:07Z","url":"https://github.com/python/cpython/issues/148947"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:a83fe103-d13d-6462-f9ef-db411eeacf46 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 838C:29AEE8:3652773:4852E7B:6B02086D |
| html-safe-nonce | 3a1eafec0d37035d8e6e97949ded55aa3a36f4007be62d63f657fdb124366333 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzhDOjI5QUVFODozNjUyNzczOjQ4NTJFN0I6NkIwMjA4NkQiLCJ2aXNpdG9yX2lkIjoiMjk3OTcyNjMzMDM5MzkyMTY0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | da4e31647ee4758735591f04353bba2a7f019c16094fa734a24f81c814ac1131 |
| hovercard-subject-tag | issue:4320467826 |
| 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/148947/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e5dc4d4e575bfbf98567142fcc1022660bdb320416d605487a26f80ddda1dae6/python/cpython/issues/148947 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e5dc4d4e575bfbf98567142fcc1022660bdb320416d605487a26f80ddda1dae6/python/cpython/issues/148947 |
| og:image:alt | Bug report Bug description: On Python 3.14, this code: def maker(): if False: __class__ = 42 def method(self): return __class__ return method from dataclasses import dataclass @dataclass(slots=True... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width