no warning when `dataclass` extends non-dataclass with an `__init__` method
Open
Nobody has claimed this yet.
bug
priority-2-low
topic-dataclasses
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
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'?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the minimal Python reproducer in the issue and tracing how dataclass inheritance is analyzed. Determine whether this case should produce a diagnostic, then add a regression test covering the missing warning and verify that the test suite passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100