Browse by Topic

Popular

Latest

Latest Posts

Illustration of Python dataclass instances being sorted by fields using the order parameter
Python

Python Dataclass Order: Sorting with order=True

Learn how order=True in Python dataclasses generates comparison methods, sorts instances, and customizes field ordering.

dataclasspythonsortingcomparison
A stylized padlock integrated with a Python code snippet, representing immutable frozen dataclasses.
Python

Frozen Dataclasses in Python: Making Data Immutable

Learn how frozen dataclasses work in Python. This article covers frozen=True syntax, shallow immutability, hashability, replace(), slots, and when to use them.

dataclassesimmutabilityPythonobject-oriented programming
Illustration of a Python dataclass with a default factory creating fresh list objects for each instance
Python

Python Dataclass Default Factory: Safe Mutable Defaults

python dataclass default factory: Learn how to use default_factory in Python dataclasses to safely handle mutable default values like lists and dicts, with practical e...

dataclassesdefault_factorymutable defaultspython
Illustration of Python dataclass default values showing a shared mutable list versus per-instance default_factory lists.
Python

How Python Dataclass Default Values Work

Python dataclass default values: how immutable defaults work, why mutable defaults raise an error, and when to use default_factory for independent per-instance state.

pythondataclassesdefault_factorymutable-defaults
Illustration of Python dataclass fields with typed attributes and default values
Python

Python Dataclass Fields: Syntax, Defaults, and Options

Learn how to declare, configure, and manage Python dataclass fields, including defaults, field() options, mutable defaults, slots, and common pitfalls.

dataclassespythontype hintsfield defaults
Illustration of a Python dataclass decorator generating class methods from field declarations
Python

Using the Python Dataclass Decorator for Cleaner Classes

Learn how Python's @dataclass decorator generates __init__, __repr__, and comparison methods, plus field defaults, frozen mode, ordering, slots, and common pitfalls.

dataclassesPythontype hintscode generation
A clean illustration of a Python dataclass transforming a cluttered class definition into a concise structured data container.
Python

Python Dataclass: Simplify Data Containers

Learn how Python dataclasses reduce boilerplate for data containers, with practical examples of defaults, immutability, ordering, and performance tradeoffs.

dataclasspythondata structuresobject-oriented programming
Diagram showing a Protocol interface with multiple concrete classes satisfying it structurally.
Python

Understanding Python Structural Typing with Protocol

Learn how Python structural typing with Protocol defines flexible type contracts without inheritance, when to use runtime_checkable, and where the approach has limits. Includes generic protocol examples.

PythonType HintsProtocolDuck Typing
Illustration comparing Python Protocol and Abstract Base Class interface definitions
Python

Python Protocol vs Abstract Base Class

Compare Python's Protocol and Abstract Base Class for defining interfaces. See how ABCs enforce contracts at runtime, how Protocols use structural typing, and when to choose each.

typingabstract-base-classprotocolstructural-typing
Python protocol structural subtyping concept with a shape interface and multiple concrete classes
Python

Using Python Typing Protocol for Structural Subtyping

Learn how to use Python's typing.Protocol for structural subtyping: define protocols, enable runtime checks, and apply them in dependency injection and plugin architectures.

typingprotocolsstructural subtypingtype hints