Search the archive

14,369 indexed articles, 13,297 of them summarised by us.

Articles
14,369
Research papers
91,965
Models priced
2,253
Providers
163

1 results for “Christian Hammond”

Newest and most relevant first

Tip: Use keyword-only arguments in Python dataclasses

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.

Simon Willison’s Weblog →