Skip to content

no warning when dataclass extends non-dataclass with an __init__ method #13051

Open
@DetachHead

Description

@DetachHead
from dataclasses import dataclass


class Foo:
    def __init__(self, value: int) -> None:
        self.value = value  # never gets run


@dataclass
class Bar(Foo):
    value2: int


Bar(1).value  # runtime error but no mypy error

playground

not sure if this is supposed to be allowed but either way this fails at runtime, so mypy should warn about it:

AttributeError: 'Bar' object has no attribute 'value'. Did you mean: 'value2'?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions