code: def all_partitions(mechanism, purview, node_labels=None):
      
      for mechanism_partition in partitions(mechanism):
          mechanism_partition.append([])
          n_mechanism_parts = len(mechanism_partition)
          max_purview_partition = min(len(purview), n_mechanism_parts)
          for n_purview_parts in range(1, max_purview_partition + 1):
              n_empty = n_mechanism_parts - n_purview_parts
              for purview_partition in k_partitions(purview, n_purview_parts):
                  purview_partition = [tuple(_list)
                                       for _list in purview_partition]
                  # Extend with empty tuples so purview partition has same size
                  # as mechanism purview
                  purview_partition.extend([()] * n_empty)
  
                  # Unique permutations to avoid duplicates empties
                  for purview_permutation in set(
                          permutations(purview_partition)):
  
                      parts = [
                          Part(tuple(m), tuple(p))
                          for m, p in zip(mechanism_partition,
                                          purview_permutation)
                      ]
  
                      # Must partition the mechanism, unless the purview is fully
                      # cut away from the mechanism.
                      if parts[0].mechanism == mechanism and parts[0].purview:
                          continue
  
                      yield KPartition(*parts, node_labels=node_labels)
docs: Return all possible partitions of a mechanism and purview.
  
      Partitions can consist of any number of parts.
  
      Args:
          mechanism (tuple[int]): A mechanism.
          purview (tuple[int]): A purview.
  
      Yields:
          KPartition: A partition of this mechanism and purview into ``k`` parts.