Skip to content

Python @dataclasses(slots=True) breaks super() #132544

Closed as not planned
Closed as not planned
@rdong8

Description

@rdong8

Bug report

Bug description:

import abc
import dataclasses
import typing


SLOTS = False


@dataclasses.dataclass(slots=SLOTS)
class Base:
    @abc.abstractmethod
    def f(self) -> None:
        pass


@dataclasses.dataclass(slots=SLOTS)
class Derived(Base):
    @typing.override
    def f(self) -> None:
        super().f()


d = Derived()
d.f()

If SLOTS = False, then this works. If SLOTS = True, then it fails:

Traceback (most recent call last):
  File "/app/output.s", line 24, in <module>
    d.f()
    ~~~^^
  File "/app/output.s", line 20, in f
    super().f()
    ^^^^^^^^^
TypeError: super(type, obj): obj (instance of Derived) is not an instance or subtype of type (Derived).

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions