Repository: oumi-ai/oumi
File: src/oumi/core/synthesis/planner.py (Python)

Code before:
        example_sources: Optional[list[ExampleSource]],
    ) -> list[list[dict]]:
        """Read examples from the example sources."""
        if example_sources is None or len(example_sources) == 0:
            return []

        results = [example_source.examples for example_source in example_sources]
        return results

    def _ingest_dataset_sources(
        self,
        dataset_sources: Optional[list[DatasetSource]],
    ) -> list[list[dict]]:
        """Read in datasets from the dataset sources."""
        if dataset_sources is None or len(dataset_sources) == 0:
            return []

        data_reader = DatasetReader()
        return [data_reader.read(dataset_source) for dataset_source in dataset_sources]

    def _ingest_document_sources(
        self,
        document_sources: Optional[list[DocumentSource]],
    ) -> list[list[dict]]:
        """Read documents from the document sources and segment them if necessary."""
        if document_sources is None or len(document_sources) == 0:
            return []

        document_reader = DocumentReader()
        per_source_records = []
        for document_source in document_sources:
            records = []
            path = document_source.path
            documents = document_reader.read(path)
            if document_source.segmentation_params is None:
                for document in documents:
                    records.append({document_source.id: document})
            else:
                segmenter = DocumentSegmenter(document_source.segmentation_params)
                for document in documents:
                    segments = segmenter.segment(document)
                    for segment in segments:
                        record = {document_source.segmentation_params.id: segment}
                        if document_source.segmentation_params.keep_original_text:
                            record[document_source.id] = document
                        records.append(record)

            per_source_records.append(records)

        return per_source_records


Review comment (suggestion):
alternatively:
```
if not document_sources:
   ...
```

Code after:
        example_sources: Optional[list[ExampleSource]],
    ) -> list[list[dict]]:
        """Read examples from the example sources."""
        if example_sources is None or len(example_sources) == 0:
            return []

        results = [example_source.examples for example_source in example_sources]
        return results

    def _ingest_dataset_sources(
        self,
        dataset_sources: Optional[list[DatasetSource]],
    ) -> list[list[dict]]:
        """Read in datasets from the dataset sources."""
        if dataset_sources is None or len(dataset_sources) == 0:
            return []

        data_reader = DatasetReader()
        return [data_reader.read(dataset_source) for dataset_source in dataset_sources]

    def _ingest_document_sources(
        self,
        document_sources: Optional[list[DocumentSource]],
    ) -> list[list[dict]]:
        """Read documents from the document sources and segment them if necessary."""
        if not document_sources:
            return []

        document_reader = DocumentReader()
        per_source_records = []
        for document_source in document_sources:
            records = []
            path = document_source.path
            documents = document_reader.read(path)
            if document_source.segmentation_params is None:
                for document in documents:
                    records.append({document_source.id: document})
            else:
                segmenter = DocumentSegmenter(document_source.segmentation_params)
                for document in documents:
                    segments = segmenter.segment(document)
                    for segment in segments:
                        record = {document_source.segmentation_params.id: segment}
                        if document_source.segmentation_params.keep_original_text:
                            record[document_source.id] = document
                        records.append(record)

            per_source_records.append(records)

        return per_source_records