python / python/mypy

Special dunder attributes on dataclass not treated as `__init__` args

Open
#20,819 6 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.