-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
Description
Bug Report
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
from typing import dataclass_transform, reveal_type
@dataclass_transform()
class Base:
def __init__( self, a: int ) -> None:
pass
class DerivedNoFields( Base ):
pass
class DerivedWithFields( Base ):
b: str
reveal_type( DerivedNoFields.__init__ )
reveal_type( DerivedWithFields.__init__ )
Expected Behavior
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)"
Your Environment
- Mypy version used: 3.16.1
- Python version used: 3.13
- No command-line flags or configuration options