Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bwagner opened this issue Mar 15, 2025 · 4 comments
Closed

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

bwagner opened this issue Mar 15, 2025 · 4 comments
Labels
stdlib Python modules in the Lib dir topic-dataclasses

Comments

@bwagner
Copy link
Contributor

bwagner commented Mar 15, 2025

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

@bwagner bwagner added the type-bug An unexpected behavior, bug, or error label Mar 15, 2025
@picnixz picnixz added stdlib Python modules in the Lib dir topic-dataclasses labels Mar 15, 2025
@sharktide
Copy link
Contributor

Would you like me to make a pull request?

@JelleZijlstra
Copy link
Member

The existing error seems correct to me. The function is defined as taking zero arguments but is passed one (self).

@sharktide
Copy link
Contributor

Got it

@picnixz
Copy link
Member

picnixz commented Mar 15, 2025

The existing error seems correct to me. The function is defined as taking zero arguments but is passed one (self).

Ah right. I haven't actually checked the report (I forgot about it). So I'm closing it as a not an issue. (Should have triaged a bit more, so thanks Jelle).

@picnixz picnixz closed this as not planned Won't fix, can't repro, duplicate, stale Mar 15, 2025
@picnixz picnixz removed the type-bug An unexpected behavior, bug, or error label Mar 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-dataclasses
Projects
None yet
Development

No branches or pull requests

4 participants