Follow-up · depth 2
What are common failure modes of dataclasses and __slots__?
What are common failure modes of dataclasses and __slots__?
Answers use simple, clear English.
Audio N/AQuick interview answer
Common failures around dataclasses and __slots__: blocking the hot path, ignoring backpressure, and weak timeout/retry design. Mutable default list in dataclass field; forgetting frozen for dict keys.
Detailed answer
Failure modes for dataclasses and __slots__: Known pitfalls: Mutable default list in dataclass field; forgetting frozen for dict keys. • Missing timeouts / unbounded retries • No backpressure when downstream slows • Assuming ordering/guarantees the runtime does not provide How seniors prevent them: Use field(default_factory=list); kw_only=True for clarity in large models. Parent context: Baseline: @dataclass auto-generates __init__, __repr__, __eq__. slots=True (Py3.10+) fixes attributes and saves memory.
Full explanation
Name concrete failure modes and the mitigation for each — that scores higher than a vague “it can fail.” @dataclass auto-generates __init__, __repr__, __eq__. slots=True (Py3.10+) fixes attributes and saves memory. frozen=True makes instances hashable if all fields hashable.
Follow-up questions
Only answered follow-ups are shown — click to open with full answers
Parent context — dataclasses and __slots__
Baseline: @dataclass auto-generates __init__, __repr__, __eq__. slots=True (Py3.10+) fixes attributes and saves memory.
View full parent question →