diff --git a/arkindex/images/managers.py b/arkindex/images/managers.py index d3d97692560fdda9ab318a43b21e20e53f387d0b..61ffb364bbc729af6b505c277a08e00f33564dd0 100644 --- a/arkindex/images/managers.py +++ b/arkindex/images/managers.py @@ -47,7 +47,7 @@ class ImageServerManager(models.Manager): f'The URL "{url}" does not match any existing image server. ' "Please ask an instance administrator to register the IIIF server for this image." ) - elif servers_count > 1: + if servers_count > 1: raise self.model.MultipleObjectsReturned( f'The URL "{url}" matched multiple existing image servers' ) diff --git a/arkindex/images/models.py b/arkindex/images/models.py index aecc25fca690b179e55696ab1f9775179b18d830..8b904acaf919c199d8ce862d12280b5da03dd7f4 100644 --- a/arkindex/images/models.py +++ b/arkindex/images/models.py @@ -108,7 +108,7 @@ class ImageServer(models.Model): src_url, dest_url = map(urllib.parse.urlsplit, (self.url, other.url)) if src_url.scheme != dest_url.scheme: raise ValueError("Cannot merge into an image server of a different protocol") - elif src_url.netloc != dest_url.netloc: + if src_url.netloc != dest_url.netloc: raise ValueError("Cannot merge into an image server on a different domain") # Check paths diff --git a/arkindex/process/api.py b/arkindex/process/api.py index f31c615adb1472d5291570d14eb6ea60fce25f5e..8d478b2aa93aa37c3a672396b78b3f69ece42771 100644 --- a/arkindex/process/api.py +++ b/arkindex/process/api.py @@ -427,9 +427,9 @@ class ProcessRetry(ProcessACLMixin, ProcessQuerysetMixin, GenericAPIView): # Allow 'retrying' a process that has no Ponos tasks (that has never been started) if len(process.tasks.all()) and state in (State.Unscheduled, State.Pending): raise ValidationError({"__all__": ["This process is already pending"]}) - elif state == State.Running: + if state == State.Running: raise ValidationError({"__all__": ["This process is already running"]}) - elif state == State.Stopping: + if state == State.Stopping: raise ValidationError({"__all__": ["This process is stopping"]}) @extend_schema( diff --git a/arkindex/process/serializers/imports.py b/arkindex/process/serializers/imports.py index 2e01179db67c303ef789998bd1e7ece990400e3e..23e601754682282d108caba5b82ca3d5cea3180f 100644 --- a/arkindex/process/serializers/imports.py +++ b/arkindex/process/serializers/imports.py @@ -545,7 +545,7 @@ class ApplyProcessTemplateSerializer(ProcessACLMixin, serializers.Serializer): access_level = self.process_access_level(process) if not access_level: raise ValidationError(detail="Process with this ID does not exist.") - elif access_level < Role.Contributor.value: + if access_level < Role.Contributor.value: raise PermissionDenied(detail="You do not have a contributor access to this process.") errors = [] @@ -627,7 +627,7 @@ class CorpusProcessSerializer(serializers.Serializer): access_level = get_max_level(self.context["request"].user, corpus) if not access_level: raise ValidationError(["Corpus with this ID does not exist."]) - elif access_level < Role.Admin.value: + if access_level < Role.Admin.value: raise ValidationError(["You do not have an admin access to this corpus."]) return corpus diff --git a/arkindex/training/api.py b/arkindex/training/api.py index 66b6d00a377014677c08e54e7a3e8dcb5df39336..c7d7220ae96ece53f8fd0426cbd0f8d93f4396d6 100644 --- a/arkindex/training/api.py +++ b/arkindex/training/api.py @@ -417,8 +417,7 @@ class ModelsList(TrainingModelMixin, ListCreateAPIView): "id": str(existing_model.id), "name": "A model with this name already exists", }) - else: - raise PermissionDenied() + raise PermissionDenied() return serializer.save() @@ -753,7 +752,7 @@ class DatasetSetBase(): ) if self.request.method == "DELETE" and not Corpus.objects.admin(self.request.user).filter(pk=dataset.corpus_id).exists(): raise PermissionDenied(detail="You do not have admin access to this dataset.") - elif self.request.method != "DELETE" and not Corpus.objects.writable(self.request.user).filter(pk=dataset.corpus_id).exists(): + if self.request.method != "DELETE" and not Corpus.objects.writable(self.request.user).filter(pk=dataset.corpus_id).exists(): raise PermissionDenied(detail="You do not have contributor access to this dataset.") if dataset.state != DatasetState.Open: raise ValidationError(detail="You can only add or update sets from a dataset in an open state.") diff --git a/ruff.toml b/ruff.toml index 5899ec4ebeb3eebb47341756a4a0e307f9bd5805..40fbb5b3b5c211b1673f37b68f51a3029d05cd4c 100644 --- a/ruff.toml +++ b/ruff.toml @@ -14,5 +14,7 @@ select = ["Q0", "F", "W", "E", "RET504", # flake8-return: superfluous-else-return "RET505", + # flake8-return: superfluous-else-raise + "RET506", ] ignore = ["E501"]