From a9f949d9449406af2f5a9323135b7c196e418504 Mon Sep 17 00:00:00 2001 From: Sergei Chertkov Date: Mon, 16 Oct 2023 15:48:28 +0100 Subject: [PATCH] Minor code cleanup --- encord/objects/ontology_labels_impl.py | 13 ++----------- encord/project.py | 3 +-- encord/user_client.py | 6 +----- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/encord/objects/ontology_labels_impl.py b/encord/objects/ontology_labels_impl.py index aa5bdbd00..d807b6c65 100644 --- a/encord/objects/ontology_labels_impl.py +++ b/encord/objects/ontology_labels_impl.py @@ -1003,13 +1003,8 @@ def _to_object_actions(self) -> Dict[str, Any]: def _to_classification_answers(self) -> Dict[str, Any]: ret: Dict[str, Any] = {} for classification in self._classifications_map.values(): - classifications = [] - all_static_answers = classification.get_all_static_answers() - for answer in all_static_answers: - if answer.is_answered(): - classifications.append(answer.to_encord_dict()) - + classifications = [answer.to_encord_dict() for answer in all_static_answers if answer.is_answered()] ret[classification.classification_hash] = { "classifications": list(reversed(classifications)), "classificationHash": classification.classification_hash, @@ -1036,12 +1031,8 @@ def _dynamic_answers_to_encord_dict(object_instance: ObjectInstance) -> List[Dic return ret def _to_encord_data_units(self) -> Dict[str, Any]: - ret = {} frame_level_data = self._label_row_read_only_data.frame_level_data - for value in frame_level_data.values(): - ret[value.image_hash] = self._to_encord_data_unit(value) - - return ret + return {value.image_hash: self._to_encord_data_unit(value) for value in frame_level_data.values()} def _to_encord_data_unit(self, frame_level_data: FrameLevelImageGroupData) -> Dict[str, Any]: ret: Dict[str, Any] = {} diff --git a/encord/project.py b/encord/project.py index baecf585b..29e8b8b3c 100644 --- a/encord/project.py +++ b/encord/project.py @@ -1001,8 +1001,7 @@ def list_collaborator_timers( Path("analytics/collaborators/timers"), params=params, result_type=Page[CollaboratorTimer] ) - for result in page.results: - yield result + yield from page.results if page.next_page_token is not None: params.page_token = page.next_page_token diff --git a/encord/user_client.py b/encord/user_client.py index d2482b7ed..829a164c1 100644 --- a/encord/user_client.py +++ b/encord/user_client.py @@ -513,11 +513,7 @@ def __get_images_paths(self, annotations_base64: str, images_directory_path: Pat @staticmethod def __get_recursive_image_paths(images_directory_path: Path) -> List[Path]: """Recursively get all the images in all the sub folders.""" - ret = [] - for file in images_directory_path.glob("**/*"): - if file.is_file(): - ret.append(file) - return ret + return [file for file in images_directory_path.glob("**/*") if file.is_file()] def __upload_cvat_images( self, images_paths: List[Path], used_base_path: Path, dataset_name: str