This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author conchylicultor
Recipients Prakhar Goel, alan_du, conchylicultor, eric.smith, jimbo1qaz_, pmpp, rhettinger, ryanhiebert, wanderrful, wyz23x2, xtreak
Date 2020-11-11.10:59:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605092352.11.0.792686807112.issue33129@roundup.psfhosted.org>
In-reply-to
Content
Solving this would significantly improve @dataclass inheritance (https://bugs.python.org/issue39300). Any idea when this will land ?

Currently, it is not possible to add required argument to a child dataclass (unless hacks like duplicating attributes):

```
import dataclasses

@dataclasses.dataclass
class A:
  x: int = 1


@dataclasses.dataclass
class B(A):
  y: int  # ERROR: non-default argument follows default argument
```

Keywords-only would solve this issue:

```
@dataclasses.dataclass
class B(A):
  y: int = dataclasses.field(kw_only=True)


B(123, y=456)
```

Note: Attrs already support this: https://www.attrs.org/en/stable/examples.html#keyword-only-attributes


For the behavior, I think there are two options:

```
class A:
  a0: int
  a1: int = field(kw_only=True)
  a2: int


class B(A):
  b0: int
  b1: int = field(kw_only=True)
  b2: int
```


Option 1: All attributes following `kw_only` are `kw_only` (kw_only indicates where to place '*')

A(a0, *, a1, a2)
B(a0, b0, *, a1, a2, b1, b2)

Option 2: `kw_only` are individually moved to the end

A(a0, a2, *, a1)
B(a0, a2, b0, b2, *, a1, b1)

I personally prefer Option 1, as it makes it easier to place the `*` with less boilerplate.

```
class Request:
  url: str
  timeout: int = field(default=-1, kw_only=True)
  verify: bool = False
  params: Optional[Dict[str, str]] = None
  cookies: Optional[Dict[str, str]] = None

Request(url, *, timeout=-1, verify=False, params=None, cookies=None)
```

Which looks better than:

```
class Request:
  url: str
  timeout: int = field(default=-1, kw_only=True)
  verify: bool = field(default=False, kw_only=True)
  params: Optional[Dict[str, str]] = field(default=None, kw_only=True)
  cookies: Optional[Dict[str, str]] = field(default=None, kw_only=True)
```
History
Date User Action Args
2020-11-11 10:59:12conchylicultorsetrecipients: + conchylicultor, rhettinger, eric.smith, pmpp, ryanhiebert, alan_du, xtreak, jimbo1qaz_, wyz23x2, wanderrful, Prakhar Goel
2020-11-11 10:59:12conchylicultorsetmessageid: <1605092352.11.0.792686807112.issue33129@roundup.psfhosted.org>
2020-11-11 10:59:12conchylicultorlinkissue33129 messages
2020-11-11 10:59:11conchylicultorcreate