docs: def topological_sort(data):
      """Topological sort the given dictionary structure.
  
      Args:
          data (dict); dictionary structure where the value is a list of dependencies for that given key.
              For example: ``{'a': (), 'b': ('a',)}``, where ``a`` depends on nothing and ``b`` depends on ``a``.
  
      Returns:
          tuple: the dependencies in constructor order
      """
  
      def check_self_dependencies(input_data):
          """Check if there are self dependencies within a node.
  
          Self dependencies are for example: ``{'a': ('a',)}``.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Raises:
              ValueError: if there are indeed self dependencies
          """
          for k, v in input_data.items():
              if k in v:
                  raise ValueError('Self-dependency, {} depends on itself.'.format(k))
  
      def prepare_input_data(input_data):
          """Prepares the input data by making sets of the dependencies. This automatically removes redundant items.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Returns:
              dict: a copy of the input dict but with sets instead of lists for the dependencies.
          """
          return {k: set(v) for k, v in input_data.items()}
  
      def find_items_without_dependencies(input_data):
          """This searches the dependencies of all the items for items that have no dependencies.
  
          For example, suppose the input is: ``{'a': ('b',)}``, then ``a`` depends on ``b`` and ``b`` depends on nothing.
          This class returns ``(b,)`` in this example.
  
          Args:
              input_data (dict): the input data. Of a structure similar to {key: (list of values), ...}.
  
          Returns:
              list: the list of items without any dependency.
          """
          return list(reduce(set.union, input_data.values()) - set(input_data.keys()))
  
      def add_empty_dependencies(data):
          items_without_dependencies = find_items_without_dependencies(data)
          data.update({item: set() for item in items_without_dependencies})
  
      def get_sorted(input_data):
          data = input_data
          while True:
              ordered = set(item for item, dep in data.items() if len(dep) == 0)
              if not ordered:
                  break
              yield ordered
              data = {item: (dep - ordered) for item, dep in data.items() if item not in ordered}
  
          if len(data) != 0:
              raise ValueError('Cyclic dependencies exist '
                               'among these items: {}'.format(', '.join(repr(x) for x in data.items())))
  
      check_self_dependencies(data)
  
      if not len(data):
          return []
  
      data_copy = prepare_input_data(data)
      add_empty_dependencies(data_copy)
  
      result = []
      for d in get_sorted(data_copy):
          try:
              d = sorted(d)
          except TypeError:
              d = list(d)
  
          result.extend(d)
      return result