(self, definition: Definition)
return _transitive_closure(definition, self._graph, networkx.DiGraph())
Compute the "transitive closure" of a given definition.
        Obtained by transitively aggregating the ancestors of this definition in the graph.

        Note: Each definition is memoized to avoid any kind of recomputation across the lifetime of this object.

        :param definition:  The Definition to get transitive closure for.
        :return:            A graph of the transitive closure of the given definition.
Compute the "transitive closure" of a given definition.
        Obtained by transitively aggregating the ancestors of this definition in the graph.
Compute the transitive closure of a given definition . Obtained by transitively aggregating the ancestors of this definition in the graph .
def transitive_closure(self, definition: Definition) -> networkx.DiGraph:
        """
        Compute the "transitive closure" of a given definition.
        Obtained by transitively aggregating the ancestors of this definition in the graph.

        Note: Each definition is memoized to avoid any kind of recomputation across the lifetime of this object.

        :param definition:  The Definition to get transitive closure for.
        :return:            A graph of the transitive closure of the given definition.
        """

        def _transitive_closure(def_: Definition, graph: networkx.DiGraph, result: networkx.DiGraph,
                                visited: Optional[Set[Definition]]=None):
            """
            Returns a joint graph that comprises the transitive closure of all defs that `def_` depends on and the
            current graph `result`. `result` is updated.
            """
            if def_ in self._transitive_closures:
                closure = self._transitive_closures[def_]
                # merge closure into result
                result.add_edges_from(closure.edges())
                return result

            if def_ not in graph:
                return result

            predecessors = list(graph.predecessors(def_))

            result.add_node(def_)
            result.add_edges_from(list(map(
                lambda e: (*e, graph.get_edge_data(*e)),
                map(
                    lambda p: (p, def_),
                    predecessors
                )
            )))

            visited = visited or set()
            visited.add(def_)
            predecessors_to_visit = set(predecessors) - set(visited)

            closure = reduce(
                lambda acc, def0: _transitive_closure(def0, graph, acc, visited),
                predecessors_to_visit,
                result
            )

            self._transitive_closures[def_] = closure
            return closure

        return _transitive_closure(definition, self._graph, networkx.DiGraph())
def transitive_closure ( self , definition : Definition ) -> networkx . DiGraph : def _transitive_closure ( def_ : Definition , graph : networkx . DiGraph , result : networkx . DiGraph , visited : Optional [ Set [ Definition ] ] = None ) : """
            Returns a joint graph that comprises the transitive closure of all defs that `def_` depends on and the
            current graph `result`. `result` is updated.
            """ if def_ in self . _transitive_closures : closure = self . _transitive_closures [ def_ ] # merge closure into result result . add_edges_from ( closure . edges ( ) ) return result if def_ not in graph : return result predecessors = list ( graph . predecessors ( def_ ) ) result . add_node ( def_ ) result . add_edges_from ( list ( map ( lambda e : ( * e , graph . get_edge_data ( * e ) ) , map ( lambda p : ( p , def_ ) , predecessors ) ) ) ) visited = visited or set ( ) visited . add ( def_ ) predecessors_to_visit = set ( predecessors ) - set ( visited ) closure = reduce ( lambda acc , def0 : _transitive_closure ( def0 , graph , acc , visited ) , predecessors_to_visit , result ) self . _transitive_closures [ def_ ] = closure return closure return _transitive_closure ( definition , self . _graph , networkx . DiGraph ( ) )