def deep_ref_retarget(obj: Any, mapping: dict) -> Any:
    """Recursively replace an indirect reference in object tree.""" 
    if type(obj) == complex:
        if obj in mapping:
            return mapping[obj]
    elif type(obj) == dict:
        for k in obj:
            obj[k] = deep_ref_retarget(obj[k], mapping)
    elif type(obj) == list:
        for k in range(len(obj)):
            obj[k] = deep_ref_retarget(obj[k], mapping)
    return obj
Recursively replace an indirect reference in object tree.
pdfsyntax/objects.py