def truncate_graph_dist(
    G: nx.MultiDiGraph,
    source_node: int,
    dist: float,
    *,
    weight: str = "length",
) -> nx.MultiDiGraph:
    """
    Remove from a graph every node beyond some network distance from a node.

    This function must calculate shortest path distances between `source_node`
    and every other graph node, which can be slow on large graphs.

    Parameters
    ----------
    G
        Input graph.
    source_node
        Node from which to measure network distances to all other nodes.
    dist
        Remove every node in the graph that is greater than `dist` distance
        (in same units as `weight` attribute) along the network from
        `source_node`.
    weight
        Graph edge attribute to use to measure distance.

    Returns
    -------
    G
        The truncated graph.
    """
    # get the shortest distance between the node and every other node
    distances = nx.shortest_path_length(G, source=source_node, weight=weight)

    # then identify every node further than dist away
    distant_nodes = {k for k, v in distances.items() if v > dist}
    unreachable_nodes = G.nodes - distances.keys()

    # make a copy to not mutate original graph object caller passed in
    G = G.copy()
    G.remove_nodes_from(distant_nodes | unreachable_nodes)

    msg = f"Truncated graph by {weight}-weighted network distance"
    utils.log(msg, level=lg.INFO)
    return G

    Remove from a graph every node beyond some network distance from a node.

    This function must calculate shortest path distances between `source_node`
    and every other graph node, which can be slow on large graphs.

    Parameters
    ----------
    G
        Input graph.
    source_node
        Node from which to measure network distances to all other nodes.
    dist
        Remove every node in the graph that is greater than `dist` distance
        (in same units as `weight` attribute) along the network from
        `source_node`.
    weight
        Graph edge attribute to use to measure distance.

    Returns
    -------
    G
        The truncated graph.
    
osmnx/truncate.py