Skip to content

Dataclasses that inherit from other dataclasses fail type-checking when explicit-override is enabled #16452

@adebrecht661

Description

@adebrecht661

Bug Report

Dataclasses that inherit from other dataclasses fail type-checking when explicit-override is enabled. This appears to be due to an unannotated override being constructed for the new & improved replace typing.

To Reproduce

from dataclasses  import dataclass

@dataclass
class Base:
    ...

@dataclass
class Child(Base):
    ...

Actual Behavior

mypy errors on Child with

Method "__mypy-replace" is not using @override but is overriding a method in class "Base" [explicit-override]

Your Environment

  • Mypy version used: 1.7.0
  • Mypy configuration options from pyproject.toml:
follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true
warn_return_any = true
strict_equality = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
enable_error_code = "explicit-override"
namespace_packages = false
  • Python version used: 3.10.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions