Skip to content

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

Closed

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

Activity

  1. self-assigned this
    on Feb 13, 2022
  2. sobolevn commented on Feb 13, 2022

    @sobolevn
    MemberAuthor

    Nope, this does not happen on master, only with #12159

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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