Skip to content

Incorrect __post_init__ order when KW_ONLY used #17564

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

Open
NeilGirdhar opened this issue Jul 22, 2024 · 0 comments
Open

Incorrect __post_init__ order when KW_ONLY used #17564

NeilGirdhar opened this issue Jul 22, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@NeilGirdhar
Copy link
Contributor

from dataclasses import dataclass, InitVar, KW_ONLY


@dataclass
class A:
    _: KW_ONLY
    x: InitVar[int]

    def __post_init__(self, x: int) -> None:
        pass


@dataclass
class C(A):
    y: InitVar[str]

    def __post_init__(self, x: int, y: str) -> None:  # Correct order.
        super().__post_init__(x)

gives

a.py:19: error: Argument 2 of "__post_init__" is incompatible with supertype "dataclass"; supertype defines the argument type as "str"  [override]
        def __post_init__(self, x: int, y: str) -> None:
                                ^~~~~~
a.py:19: error: Argument 3 of "__post_init__" is incompatible with supertype "dataclass"; supertype defines the argument type as "int"  [override]
        def __post_init__(self, x: int, y: str) -> None:
@NeilGirdhar NeilGirdhar added the bug mypy got something wrong label Jul 22, 2024
@NeilGirdhar NeilGirdhar changed the title Incorrect __post_init__ order Incorrect __post_init__ order when KW_ONLY used Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant