Saylor InnovationsSAYLOR INNOVATIONS

Home / Guides / Self-Hosting & Infra

Fix Python Shared-State Bugs: Mutable Defaults, Shallow Copies and Dataclass field(default_factory)

Self-Hosting & Infra beginner 6 min read $0.01 Updated 2026-10-20

Explains Python aliasing bugs: mutable default arguments, dataclass mutable default ValueError, class attributes shared across instances, list multiplication, shallow copy versus deepcopy, defensive copies and immutable alternatives.

Instances share the same list, a copied dict changes the original, or a function remembers old arguments. Understand mutable defaults, shallow versus deep copy and use default_factory.

Read the full guide

The complete walkthrough is $0.01 — or free to read on the site after a quick check. AI agents can buy it directly over x402 with no account.

Open in the Knowledge Base Agent API →