Skip to content

Wrong error message when failing to pass self-parameter to __post_init__ #131284

@bwagner

Description

@bwagner

Bug report

Bug description:

from dataclasses import dataclass

@dataclass
class PostInit:
    def __post_init__():
        pass

PostInit()

will yield this error message:

TypeError: PostInit.__post_init__() takes 0 positional arguments but 1 was given

where it should read:

TypeError: PostInit.__post_init__() takes 1 positional argument but 0 were given

CPython versions tested on:

3.14, 3.12, 3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-dataclasses

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions