code: def iter_import_chunks(self):
      
      chunk = []
      last_line = None
      for leaf in self.python_file.tree.body:
        if isinstance(leaf, (ast.Import, ast.ImportFrom)):
          # we've seen previous imports but this import is not in the same chunk
          if last_line and leaf.lineno != last_line[1]:
            yield chunk
            chunk = [leaf]
          # we've either not seen previous imports or this is part of the same chunk
          elif not last_line or last_line and leaf.lineno == last_line[1]:
            chunk.append(leaf)
          last_line = self.python_file.logical_lines[leaf.lineno]
      if chunk:
        yield chunk
docs: Iterate over space-separated import chunks in a file.