def flexible_deepcopy(
    obj: Any,
    on_fail: str = "raise",
    _memo: Optional[Dict[int, Any]] = None,
) -> Any:

source code

Perform a deepcopy that tolerates un‑copyable elements.Parameters

obj : Any The object you wish to copy. on_fail : , default ‘raise’ • ‘raise’ – re‑raise copy error (standard behaviour). • ‘skip’ – drop the offending element from the result. • ‘shallow’ – insert the original element unchanged. _memo : dict or None (internal) Memoisation dict to preserve identity & avoid infinite recursion.Returns

Any A deep‑copied version of obj, modified per on_fail strategy.Raises

ValueError If on_fail is not one of the accepted values. Exception Re‑raises whatever copy error occurred when on_fail == ‘raise’.