Skip to content

dataclass(slots=True) fails if method has an empty __class__ cell #148947

Description

@JelleZijlstra

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 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.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. changed the title [-]dataclass(slots=True) crashes if method has an empty `__class__` cell[/-] [+]dataclass(slots=True) fails if method has an empty `__class__` cell[/+] on Apr 24, 2026
  2. changed the title [-]dataclass(slots=True) fails if method has an empty `__class__` cell[/-] [+]dataclass(slots=True) crashes if method has an empty `__class__` cell[/+] on Apr 24, 2026
  3. added
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Apr 24, 2026
  4. changed the title [-]dataclass(slots=True) crashes if method has an empty `__class__` cell[/-] [+]dataclass(slots=True) fails if method has an empty `__class__` cell[/+] on Apr 24, 2026
  5. added a commit that references this issue on Apr 25, 2026
  6. added a commit that references this issue on Apr 25, 2026
  7. added a commit that references this issue on Apr 25, 2026
  8. added 3 commits that reference this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions