Skip to content

dataclass inheritance with defaults override raises Attributes without a default cannot follow attributes with one #12173

@sobolevn

Description

@sobolevn

This code produces a result that seems not really correct to me:

from dataclasses import dataclass, field, KW_ONLY

@dataclass
class Base:
    x: int
    y: int = field(kw_only=True)
    _: KW_ONLY
    z: int = 0

@dataclass
class Other(Base):  # E: Attributes without a default cannot follow attributes with one
    x: int
    y: int
    z: int

Why I think that it is incorrect?

  1. print(Other(1, 2, 3)) works just fine in runtime
  2. We don't really have any attributes that have defaults in Other, since all fields are overriden

Refs #12159

Metadata

Metadata

Assignees

Labels

bugmypy got something wrong

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions