Special dunder attributes on dataclass not treated as `__init__` args
Open
Nobody has claimed this yet.
bug
topic-dataclasses
topic-runtime-semantics
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
Dunder-variables on dataclasses are considered to be arguments instead of ignored, per the dataclass documentation.
To Reproduce
https://mypy-play.net/?gist=27221945829d19cc0407d970cc1cb1f8
from dataclasses import dataclass
@dataclass
class Example:
a: int
__name__: str
e = Example(1) # error: Missing positional argument "__name__" in call to "Example" [call-arg]
Python run time does not consider __name__ as a required arguments, but mypy does.
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 with the linked mypy-play reproducer and trace the dataclass handling responsible for constructing the Example call signature. Confirm the runtime behavior described in the issue, then verify that name is excluded from required init arguments and the Example(1) call no longer reports a missing argument.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100