Skip to content

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

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'?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions