Re:Use keyword-only arguments in Python dataclasses
by meander_water on Monday June 30, 2025 @05:13AM
(#44421121)
You can also explicitly specify which arguments need to be keyword only using the KW_ONLY sentinel type annotation:
[ Parent
| on HN ]
Re:Use keyword-only arguments in Python dataclasses
by mixedmath on Monday June 30, 2025 @09:44AM
(#44423189)
I've never seen this before. But yes, this does work. And that's very nice.
Thank you for the tip.
Re:Use keyword-only arguments in Python dataclasses
by chipx86 on Monday June 30, 2025 @03:39PM
(#44427047)
This is a great feature for those who want a mix of positional and keyword-only arguments.
I should have mentioned originally (and I've since updated my post) that this and the kw_only= flag both require Python 3.10 and higher, so code that works with older versions can't opt into it yet.