Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

No-field class derived fromdataclass_transform base class uses base class's constructor signature #19452

Open
@caoculus

Description

@caoculus

Bug Report

When a class derives from a base class marked withdataclass_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__ )

Playground link

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp