Skip to content

KW_ONLY should only apply to own-fields #1047

@carljm

Description

@carljm

In this example:

from dataclasses import dataclass, KW_ONLY

@dataclass
class D:
    x: int
    _: KW_ONLY
    y: str

@dataclass
class E(D):
    z: bytes

E(1, b"foo", y="foo")

The field z should not be considered keyword-only; the _: KW_ONLY in D applies only to y, not to z in the subclass.

We currently handle KW_ONLY when we synthesize the __init__ member; I think we maybe need to handle it in own_fields instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdataclassesIssues relating to dataclasses and dataclass_transform

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions