You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No-field class derived from dataclass_transform base class uses base class's constructor signature #19452
When a class derives from a base class marked with dataclass_transform and the derived class has no fields, mypy incorrectly infers that the derived class does not provide its own constructor. This issue does not happen if the derived class has any fields.
Pyright infers the correct constructor signature here.
To Reproduce
fromtypingimportdataclass_transform, reveal_type@dataclass_transform()classBase:
def__init__( self, a: int ) ->None:
passclassDerivedNoFields( Base ):
passclassDerivedWithFields( Base ):
b: strreveal_type( DerivedNoFields.__init__ )
reveal_type( DerivedWithFields.__init__ )
main.py:14: note: Revealed type is "def (self: __main__.DerivedNoFields)"
main.py:15: note: Revealed type is "def (self: __main__.DerivedWithFields, b: builtins.str)"
Actual Behavior
main.py:14: note: Revealed type is "def (self: __main__.Base, a: builtins.int)"
main.py:15: note: Revealed type is "def (self: __main__.DerivedWithFields, b: builtins.str)"
changed the title [-]No-field class derived from `dataclass_transform` base uses base class's constructor signature[/-][+]No-field class derived from `dataclass_transform` base class uses base class's constructor signature[/+]on Jul 15, 2025
Activity
[-]No-field class derived from `dataclass_transform` base uses base class's constructor signature[/-][+]No-field class derived from `dataclass_transform` base class uses base class's constructor signature[/+]sterliakov commentedon Jul 15, 2025
mypy/mypy/plugins/dataclasses.py
Lines 254 to 262 in a79e85e
There's a wrong premise in this comment, default
__init__is not always applicable. It predates@dataclass_transformand just wasn't noticed before.