code: def sort(imports, separate=True, import_before_from=True, **classify_kwargs):
      if separate:
          def classify_func(obj):
              return classify_import(
                  obj.import_statement.module, **classify_kwargs
              )
          types = ImportType.__all__
      else:
          def classify_func(obj):
              return classify_import(
                  obj.import_statement.module, **classify_kwargs
              ) == ImportType.FUTURE
          types = [True, False]
      if import_before_from:
          def sort_within(obj):
              return (CLS_TO_INDEX[type(obj)],) + obj.sort_key
      else:
          def sort_within(obj):
              return tuple(obj.sort_key)
      imports_partitioned = collections.defaultdict(list)
      for import_obj in imports:
          imports_partitioned[classify_func(import_obj)].append(import_obj)
      for segment_key, val in imports_partitioned.items():
          imports_partitioned[segment_key] = sorted(val, key=sort_within)
      return tuple(
          tuple(imports_partitioned[key])
          for key in types if key in imports_partitioned
      )