Tip: Use keyword-only arguments in Python dataclasses
AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.
Why it matters
Python developers can add fields to dataclasses and subclasses without breaking existing constructor calls, reducing refactoring risk in shared code.
Simon Willison shares a tip from developer Christian Hammond on a Python feature called dataclasses, which are shortcuts for creating classes that hold data. By adding a setting called kw_only=True, the class only accepts arguments written by name, not by position. This means new fields can be added later, including in subclasses, without breaking existing code. The tip applies to anyone writing Python.
A short link post from Simon Willison's blog passes along a tip by Christian Hammond: Python teams should define dataclasses with @dataclass(kw_only=True). This forces all constructor arguments to be passed by keyword, so adding new properties later, including in subclasses, no longer risks silently breaking code that passed arguments by position. It is a free, zero-cost coding practice, not a product announcement; no adoption data, benchmarks, or tooling is provided.
Willison links a tip from Christian Hammond: creating a Python dataclass with @dataclass(kw_only=True) makes its constructor accept only keyword arguments. This prevents positional-argument coupling, so new fields can be added to the dataclass or subclasses without breaking existing call sites. The post is a brief link share dated 29th June 2025 with no code examples, version requirements, or caveats discussed.
Read the original
This summary exists to save you time, not to replace the source.
Key terms
Python dataclass kw_only Simon Willison Christian Hammond Datasette Ladybird
Was this summary useful?
One click, anonymous. It tells us which summaries to re-run.
Related reading
Code-driven AI illustrations are more useful than images from dedicated image models
Code‑driven AI illustrations let designers edit assets directly in code, saving time on iteration and ensuring consistency, which is a game‑changer for teams that need rapid, reusable visual content.
A hierarchical note-taking app for building large personal knowledge bases
Trilium lets users build and navigate massive personal knowledge bases without duplicating content, saving time on organization and retrieval.
Desktop apps in Go with native UI or web frontend
Go developers can now ship cross‑platform desktop and mobile apps in a single small binary without cgo or heavy runtimes, cutting build complexity and deployment size.
OpenBitFun: an agent workspace with four harness modes and phone remote control
OpenBitFun lets agents run on any machine and be controlled from a phone, eliminating the need to choose between local power and remote access, saving developers time switching contexts.
Intel One Mono: a monospaced font designed with low-vision developers
Developers with low vision or eye fatigue can read code more clearly, reducing errors and improving productivity.