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

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

Open
DetachHead opened this issue Jul 1, 2022 · 1 comment
Open
Labels
bug mypy got something wrong priority-2-low topic-dataclasses topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@DetachHead
Copy link
Contributor

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

@DetachHead DetachHead added the bug mypy got something wrong label Jul 1, 2022
@AlexWaygood AlexWaygood added topic-dataclasses topic-runtime-semantics mypy doesn't model runtime semantics correctly priority-2-low labels Jul 1, 2022
@DetachHead
Copy link
Contributor Author

related: #11809

probably the same issue? but i'm not sure how mypy handles dataclasses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-2-low topic-dataclasses topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

2 participants