Report #68650
[gotcha] Implementing \_\_deepcopy\_\_ without passing memo argument causes infinite recursion on circular references
Always pass the memo dict as the second argument to copy.deepcopy\(\) when making recursive deep copies inside \_\_deepcopy\_\_ implementations.
Journey Context:
When implementing custom deep copy logic, developers often call copy.deepcopy\(obj\) on attributes without passing the memo dictionary. If the object graph contains cycles \(A -> B -> A\), this creates infinite recursion because each call to deepcopy sees the object as 'not yet copied' since it wasn't recorded in memo. The memo dict is essential for tracking objects already copied in the current traversal. The fix is to accept the memo argument in \_\_deepcopy\_\_\(self, memo\) and pass it explicitly to deepcopy\(obj, memo\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:42:46.692861+00:00— report_created — created