              for item in list_:
                  all_items.add(item)
                  # No self dependencies
                  if head != item:
                      dependency_graph[item].add(head)
                  head = item
          try:
              return stable_topological_sort(all_items, dependency_graph)
          except CyclicDependencyError:
              warnings.warn(
 
</s> remove             dependency_graph.setdefault(head, set())
 </s> add             ts.add(head) </s> remove         dependency_graph = defaultdict(set)
 </s> add         ts = TopologicalSorter() </s> remove                                 dependency_graph[op].add(op2)

            # we use a stable sort for deterministic tests & general behavior
            self.generated_operations[app_label] = stable_topological_sort(
                ops, dependency_graph
            )
 </s> add                                 ts.add(op, op2)
            self.generated_operations[app_label] = list(ts.static_order()) </s> remove             # construct a dependency graph for intra-app dependencies
            dependency_graph = {op: set() for op in ops}
 </s> add             ts = TopologicalSorter()
                    ts.add(item, head)
              for item in list_:
                  all_items.add(item)
                  # No self dependencies
                  if head != item:
                    ts.add(item, head)
                  head = item
          try:
              return stable_topological_sort(all_items, dependency_graph)
          except CyclicDependencyError:
              warnings.warn(
keep keep keep keep replace keep keep keep keep keep
 Fixed #32528 -- Replaced django.utils.topological_sort with graphlib.TopologicalSort().

graphlib.TopologicalSort() is available since Python 3.9. 
django/forms/widgets.py