From 2f790e93732f1318a55c5e8668d1fee732669b83 Mon Sep 17 00:00:00 2001 From: Yoann Schneider <yschneider@teklia.com> Date: Fri, 12 Apr 2024 19:06:27 +0200 Subject: [PATCH] Comply with RET505 --- arkindex/documents/api/ml.py | 2 +- arkindex/documents/dates.py | 2 +- arkindex/documents/tests/test_edit_elementpath.py | 2 +- arkindex/images/serializers.py | 2 +- arkindex/process/api.py | 3 +-- arkindex/process/models.py | 3 +-- arkindex/project/argparse.py | 3 +-- arkindex/project/tests/test_config.py | 2 +- .../training/management/commands/migrate_workers.py | 4 ++-- arkindex/users/api.py | 11 +++++------ ruff.toml | 2 ++ 11 files changed, 17 insertions(+), 19 deletions(-) diff --git a/arkindex/documents/api/ml.py b/arkindex/documents/api/ml.py index 7e852fc139..62fea8eafa 100644 --- a/arkindex/documents/api/ml.py +++ b/arkindex/documents/api/ml.py @@ -440,7 +440,7 @@ class ManageClassificationsSelection(SelectionMixin, CorpusACLMixin, CreateAPIVi mode = serializer.validated_data["mode"] if mode == ClassificationMode.Create: return self.create(corpus, request, *args, **kwargs) - elif mode == ClassificationMode.Validate: + if mode == ClassificationMode.Validate: elements = self.get_selection(corpus.id) Classification.objects.filter( element__in=elements, diff --git a/arkindex/documents/dates.py b/arkindex/documents/dates.py index 10643931a2..dc3012bef8 100644 --- a/arkindex/documents/dates.py +++ b/arkindex/documents/dates.py @@ -45,7 +45,7 @@ class InterpretedDate(object): """ if self.month and self.day: return DatePrecision.Day - elif self.month: + if self.month: return DatePrecision.Month return DatePrecision.Year diff --git a/arkindex/documents/tests/test_edit_elementpath.py b/arkindex/documents/tests/test_edit_elementpath.py index 21455699fd..ac0f945e98 100644 --- a/arkindex/documents/tests/test_edit_elementpath.py +++ b/arkindex/documents/tests/test_edit_elementpath.py @@ -363,7 +363,7 @@ class TestEditElementPath(FixtureTestCase): path_id = elements["B"].paths.get().id if path1.id == path_id: return str(path1.path[0]) - elif path2.id == path_id: + if path2.id == path_id: return str(path2.path[0]) raise AssertionError("Unexpected top-level path ID") diff --git a/arkindex/images/serializers.py b/arkindex/images/serializers.py index 1b0805674f..bef4751cb1 100644 --- a/arkindex/images/serializers.py +++ b/arkindex/images/serializers.py @@ -68,7 +68,7 @@ class ImageSerializer(serializers.ModelSerializer): if not self.instance: # Force the Unchecked status when creating a new image return S3FileStatus.Unchecked - elif value == S3FileStatus.Checked: + if value == S3FileStatus.Checked: # Perform image validation if we are updating an existing image to Checked try: if self.instance.server.s3_bucket and not self.instance.server.s3_read_only_bucket: diff --git a/arkindex/process/api.py b/arkindex/process/api.py index e6c154ea70..f31c615adb 100644 --- a/arkindex/process/api.py +++ b/arkindex/process/api.py @@ -1579,8 +1579,7 @@ class ListProcessElements(CorpusACLMixin, ListAPIView): def get_serializer_class(self): if self.with_image: return ProcessElementSerializer - else: - return ProcessElementLightSerializer + return ProcessElementLightSerializer def get_queryset(self): if not self.has_admin_access(self.process.corpus): diff --git a/arkindex/process/models.py b/arkindex/process/models.py index 94d0412029..8e8dff5625 100644 --- a/arkindex/process/models.py +++ b/arkindex/process/models.py @@ -232,8 +232,7 @@ class Process(IndexableModel): """ if self.has_prefetched_tasks: return max((t.expiry for t in self.tasks.all()), default=None) - else: - return self.tasks.aggregate(models.Max("expiry"))["expiry__max"] + return self.tasks.aggregate(models.Max("expiry"))["expiry__max"] def get_last_run(self) -> int: """ diff --git a/arkindex/project/argparse.py b/arkindex/project/argparse.py index 7f0f9330c6..bbb3dcf17c 100644 --- a/arkindex/project/argparse.py +++ b/arkindex/project/argparse.py @@ -37,8 +37,7 @@ class ModelArgument(object): text_filter = {f"{self.text_search_field}__{self.text_search_lookup}": arg} if self.many: return qs.filter(**text_filter) - else: - return qs.get(**text_filter) + return qs.get(**text_filter) class CorpusArgument(ModelArgument): diff --git a/arkindex/project/tests/test_config.py b/arkindex/project/tests/test_config.py index 4a046d010a..ec9eb25440 100644 --- a/arkindex/project/tests/test_config.py +++ b/arkindex/project/tests/test_config.py @@ -26,7 +26,7 @@ class TestConfig(TestCase): data = data.value if data is None: return self.represent_none(data) - elif isinstance(data, (bool, int, float, bytes, str)): + if isinstance(data, (bool, int, float, bytes, str)): return self.represent_data(data) return self.represent_str(str(data)) diff --git a/arkindex/training/management/commands/migrate_workers.py b/arkindex/training/management/commands/migrate_workers.py index 51e1516508..6e011fe5a6 100644 --- a/arkindex/training/management/commands/migrate_workers.py +++ b/arkindex/training/management/commands/migrate_workers.py @@ -23,7 +23,7 @@ def ask(phrase): choice = input(phrase + " [y/n]: ") if choice.lower() == "y": return True - elif choice.lower() == "n": + if choice.lower() == "n": return False @@ -33,7 +33,7 @@ def choose(instances, name_field="name", title="Pick one item", allow_skip=False nb = instances.count() if nb == 0: return - elif nb == 1: + if nb == 1: return instances.first() # Build internal representation diff --git a/arkindex/users/api.py b/arkindex/users/api.py index 5c4b9c40df..467fd2e728 100644 --- a/arkindex/users/api.py +++ b/arkindex/users/api.py @@ -261,12 +261,11 @@ class PasswordReset(CreateAPIView): status=status.HTTP_201_CREATED, headers=headers, ) - else: - return Response( - form.errors.get_json_data(), - status=status.HTTP_400_BAD_REQUEST, - headers=self.default_response_headers - ) + return Response( + form.errors.get_json_data(), + status=status.HTTP_400_BAD_REQUEST, + headers=self.default_response_headers + ) @extend_schema_view(post=extend_schema(operation_id="PasswordResetConfirm", tags=["users"])) diff --git a/ruff.toml b/ruff.toml index c32e4d8b50..5899ec4ebe 100644 --- a/ruff.toml +++ b/ruff.toml @@ -12,5 +12,7 @@ select = ["Q0", "F", "W", "E", "RET501", # flake8-return: unnecessary-assign "RET504", + # flake8-return: superfluous-else-return + "RET505", ] ignore = ["E501"] -- GitLab