Re:Attrs – the Python library everyone needs (2016)
by nurettin on Friday December 24, 2021 @11:21PM
(#29680363)
dataclasses have methods for iterating fields and inspecting types, so any feature can be added. There is also the benefit of type checking. My grief with dataclasses is how I can't inherit from dataclasses with default fields without making all child class fields also have defaults.
[ Parent
| on HN ]
Re:Attrs – the Python library everyone needs (2016)
by ericvsmith on Saturday December 25, 2021 @02:58AM
(#29681371)
dataclasses author here.
Does the keyword-only feature in 3.10 help you at all?
Re:Attrs – the Python library everyone needs (2016)
by abdusco on Saturday December 25, 2021 @03:35AM
(#29681516)
Wow, I was unaware of this feature. It appears there are 3 ways to declare fields as keyword-only.
@dataclass(kw_only=True)
class Birthday:
name: str
birthday: datetime.date
# ---
@dataclass
class Birthday:
name: str
birthday: datetime.date = field(kw_only=True)
# ---
from dataclasses import KW_ONLY
@dataclass
class Point:
x: float
y: float
_: KW_ONLY
z: float = 0.0
t: float = 0.0
https://docs.python.org/3/whatsnew/3.10.html#keyword-only-fi...