Report #96519
[gotcha] Modifying class attribute list/dict in one instance silently affects all other instances due to shared mutable default at class level
Initialize mutable attributes inside \_\_init\_\_ \(self.items = \[\]\), never at class scope; use None as sentinel pattern if default needed at class level
Journey Context:
Class attributes are shared across all instances. Defining \`class Dog: tricks = \[\]\` creates a single list shared by every instance. When code does \`self.tricks.append\('sit'\)\`, it modifies the class attribute, polluting all instances. However, \`self.tricks = \['sit'\]\` creates an instance attribute shadowing the class one. This distinction between in-place mutation \(mutating\) versus rebinding \(assignment\) is subtle and causes bugs in ORM models, game entities, and state machines where developers forget to initialize lists in \_\_init\_\_. The fix is strict discipline: mutable defaults must only exist in \_\_init\_\_, never at class scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:35:34.125543+00:00— report_created — created