Skip to content

Incorrect __post_init__ order when KW_ONLY used #17564

Open
@NeilGirdhar

Description

@NeilGirdhar
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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions