def find_path(source_id: int, target_id: int) -> Optional[serial_utils.Lens]:
    """Find the reference path between two Python objects by their id.

    Returns None if a path is not found. Tries to describe the path in terms of
    dictionary or array lookups but may fall back to referents which only
    indicate that an object is linked to another as per Python's GC but how the
    link is represented is not known to us.
    """

    visited: Set[int] = set()
    queue: Queue[Tuple[serial_utils.Lens, List[RefLike]]] = Queue()

    source_ref = RefLike(ref_id=source_id)
    queue.put((serial_utils.Lens(), [source_ref]))

    prog = tqdm(total=len(gc.get_objects()))

    def skip_val(val):
        if val is None:
            return True
        if not gc.is_tracked(val):
            return True
        if gc.is_finalized(val):
            return True
        try:
            if weakref.CallableProxyType.__instancecheck__(val):
                return True
            if weakref.ReferenceType.__instancecheck__(val):
                return True
            if weakref.ProxyType.__instancecheck__(val):
                return True
        except Exception:
            return False
        if id(val) in visited:
            return True

        return False

    biggest_len = 0

    while not queue.empty():
        lens, path = queue.get()

        prog.update(len(visited) - prog.n)

        if len(path) > biggest_len:
            biggest_len = len(path)

            if len(path) < 15:
                prog.set_description_str(str(lens))
            else:
                prog.set_description_str(f"lens with {len(path)} steps")
            prog.set_postfix_str(
                text_utils.format_size(len(visited)) + " reference(s) visited"
            )

        final_ref = path[-1]
        if final_ref.ref_id == target_id:
            return lens

        final = final_ref.get()

        if isinstance(final, dict):
            for key, value in list(final.items()):
                if skip_val(value):
                    continue

                value_ref = RefLike(obj=value)
                visited.add(value_ref.ref_id)

                if isinstance(key, str):
                    queue.put((
                        lens + serial_utils.GetItem(item=key),
                        path + [value_ref],
                    ))
                else:
                    queue.put((
                        lens + GetReferent(ref_id=value_ref.ref_id),
                        path + [value_ref],
                    ))

        elif isinstance(final, (list, tuple)):
            for index, value in enumerate(final):
                if skip_val(value):
                    continue

                value_ref = RefLike(obj=value)
                visited.add(value_ref.ref_id)

                queue.put((
                    lens + serial_utils.GetIndex(index=index),
                    path + [value_ref],
                ))

                del value

        else:
            for value in gc.get_referents(final):
                if skip_val(value):
                    continue

                value_ref = RefLike(obj=value)
                visited.add(value_ref.ref_id)

                queue.put((
                    lens + GetReferent(ref_id=value_ref.ref_id),
                    path + [value_ref],
                ))

                del value

    return None
Find the reference path between two Python objects by their id.

    Returns None if a path is not found. Tries to describe the path in terms of
    dictionary or array lookups but may fall back to referents which only
    indicate that an object is linked to another as per Python's GC but how the
    link is represented is not known to us.
    
tests/utils.py