From 9a65abf6b81038128f0c0977d9ecb132a7292382 Mon Sep 17 00:00:00 2001 From: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com> Date: Mon, 23 Dec 2024 10:54:16 -0800 Subject: [PATCH] removed some redundancies (#1796) * removed some redundancies * cleanup --- .../source/base_file_knowledge_source.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/crewai/knowledge/source/base_file_knowledge_source.py b/src/crewai/knowledge/source/base_file_knowledge_source.py index e086cbf659..8cee77e168 100644 --- a/src/crewai/knowledge/source/base_file_knowledge_source.py +++ b/src/crewai/knowledge/source/base_file_knowledge_source.py @@ -71,28 +71,29 @@ def convert_to_path(self, path: Union[Path, str]) -> Path: def _process_file_paths(self) -> List[Path]: """Convert file_path to a list of Path objects.""" - # Check if old file_path is being used if hasattr(self, "file_path") and self.file_path is not None: self._logger.log( "warning", "The 'file_path' attribute is deprecated and will be removed in a future version. Please use 'file_paths' instead.", color="yellow", ) - paths = ( - [self.file_path] - if isinstance(self.file_path, (str, Path)) - else self.file_path + self.file_paths = self.file_path + + if self.file_paths is None: + raise ValueError("Your source must be provided with a file_paths: []") + + # Convert single path to list + path_list: List[Union[Path, str]] = ( + [self.file_paths] + if isinstance(self.file_paths, (str, Path)) + else list(self.file_paths) + if isinstance(self.file_paths, list) + else [] + ) + + if not path_list: + raise ValueError( + "file_path/file_paths must be a Path, str, or a list of these types" ) - else: - if self.file_paths is None: - raise ValueError("Your source must be provided with a file_paths: []") - elif isinstance(self.file_paths, list) and len(self.file_paths) == 0: - raise ValueError("Empty file_paths are not allowed") - else: - paths = ( - [self.file_paths] - if isinstance(self.file_paths, (str, Path)) - else self.file_paths - ) - return [self.convert_to_path(path) for path in paths] + return [self.convert_to_path(path) for path in path_list]