Skip to content

Special dunder attributes on dataclass not treated as __init__ args #20819

@ktbarrett

Description

@ktbarrett

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions