Category: typing

← Back to all posts

Types That Can't Lie: Safe Type Modeling in Python

pythontyping·by Adrian Benavides·September 2, 2026·6 min read

A string field accepts anything, and the crash lands far from the cause. Design Python types that can't lie: value objects, canonical enums, and tagged unions the type checker can rely on.

Immutability and Defensive State Design in Python

pythontyping·by Adrian Benavides·August 6, 2026·8 min read

Frozen dataclasses are the default for domain value objects, but they don't validate at runtime. msgspec.Struct closes that gap with a single type that decodes, validates, and stays immutable across the wire boundary and the domain layer. attrs and cattrs cover the same ground in two libraries, and pydantic is only worth it when the ecosystem integration matters.