From fec268dc1abfd60fd457246b3e2f09445d762723 Mon Sep 17 00:00:00 2001
From: Yoann Schneider <yschneider@teklia.com>
Date: Fri, 12 Apr 2024 19:01:13 +0200
Subject: [PATCH] Comply with RET503

---
 arkindex/documents/date_parser.py          | 1 +
 arkindex/documents/dates.py                | 1 +
 arkindex/documents/serializers/elements.py | 2 ++
 arkindex/images/serializers.py             | 1 +
 arkindex/ponos/utils.py                    | 1 +
 arkindex/process/serializers/files.py      | 2 ++
 arkindex/project/admin.py                  | 1 +
 arkindex/project/fields.py                 | 1 +
 arkindex/project/tests/__init__.py         | 1 +
 ruff.toml                                  | 2 ++
 10 files changed, 13 insertions(+)

diff --git a/arkindex/documents/date_parser.py b/arkindex/documents/date_parser.py
index 47a0ffb031..932083d4fb 100644
--- a/arkindex/documents/date_parser.py
+++ b/arkindex/documents/date_parser.py
@@ -99,6 +99,7 @@ def year_month_str(raw_date):
             "month": months[0],
             "type": DateType.Exact
         }, )
+    return None
 
 
 def year_year(raw_date):
diff --git a/arkindex/documents/dates.py b/arkindex/documents/dates.py
index 34bfa85281..f3ed94e343 100644
--- a/arkindex/documents/dates.py
+++ b/arkindex/documents/dates.py
@@ -68,6 +68,7 @@ class InterpretedDate(object):
             if s == o:
                 continue
             return s > o
+        return None
 
     def __str__(self):
         return "-".join("{:02d}".format(e) for e in tuple(self) if e)
diff --git a/arkindex/documents/serializers/elements.py b/arkindex/documents/serializers/elements.py
index ad9b227200..59680a3d13 100644
--- a/arkindex/documents/serializers/elements.py
+++ b/arkindex/documents/serializers/elements.py
@@ -380,6 +380,7 @@ class ElementTinySerializer(serializers.ModelSerializer):
     def get_thumbnail_url(self, element):
         if element.type.folder:
             return element.thumbnail.s3_url
+        return None
 
     @extend_schema_field(CorpusLightSerializer(read_only=True))
     def get_corpus(self, element):
@@ -632,6 +633,7 @@ class ElementSerializer(ElementTinySerializer):
     def get_thumbnail_put_url(self, element):
         if element.type.folder and self.element_rights >= Role.Admin.value:
             return element.thumbnail.s3_put_url
+        return None
 
     def update(self, instance, validated_data):
         image = validated_data.pop("image", None)
diff --git a/arkindex/images/serializers.py b/arkindex/images/serializers.py
index 05709481ea..551fa446d5 100644
--- a/arkindex/images/serializers.py
+++ b/arkindex/images/serializers.py
@@ -63,6 +63,7 @@ class ImageSerializer(serializers.ModelSerializer):
         # Only allow the S3 URL for admins or Ponos tasks
         if is_admin_or_ponos_task(self.context["request"]):
             return obj.s3_url
+        return None
 
     def validate_status(self, value):
         if not self.instance:
diff --git a/arkindex/ponos/utils.py b/arkindex/ponos/utils.py
index f9731fc17c..5ab48bfcbe 100644
--- a/arkindex/ponos/utils.py
+++ b/arkindex/ponos/utils.py
@@ -17,6 +17,7 @@ def is_admin_or_ponos_task(request):
 def get_process_from_task_auth(request):
     if isinstance(request.auth, Task):
         return request.auth.process
+    return None
 
 
 def upload_artifact(task, path, artifacts_dir):
diff --git a/arkindex/process/serializers/files.py b/arkindex/process/serializers/files.py
index 3dbc77b799..e4b7a8eee3 100644
--- a/arkindex/process/serializers/files.py
+++ b/arkindex/process/serializers/files.py
@@ -47,6 +47,8 @@ class DataFileSerializer(serializers.ModelSerializer):
             request_process = get_process_from_task_auth(request)
             if not request_process or request_process.mode in (ProcessMode.Files, ProcessMode.IIIF):
                 return obj.s3_url
+            return None
+        return None
 
 
 class DataFileCreateSerializer(serializers.ModelSerializer):
diff --git a/arkindex/project/admin.py b/arkindex/project/admin.py
index 0cb2fe12f5..14403e4eb8 100644
--- a/arkindex/project/admin.py
+++ b/arkindex/project/admin.py
@@ -20,3 +20,4 @@ class ArchivedListFilter(admin.SimpleListFilter):
             return queryset.filter(archived__isnull=False)
         if self.value() == "false":
             return queryset.filter(archived__isnull=True)
+        return None
diff --git a/arkindex/project/fields.py b/arkindex/project/fields.py
index e66f28bb13..b493d89597 100644
--- a/arkindex/project/fields.py
+++ b/arkindex/project/fields.py
@@ -57,6 +57,7 @@ class ArrayField(fields.ArrayField):
             return transform
         if name == "last":
             return LastItemTransformFactory(self.base_field)
+        return None
 
 
 class Array(Func):
diff --git a/arkindex/project/tests/__init__.py b/arkindex/project/tests/__init__.py
index c918434474..de2a1014cf 100644
--- a/arkindex/project/tests/__init__.py
+++ b/arkindex/project/tests/__init__.py
@@ -197,6 +197,7 @@ class FixtureMixin(object):
 
         with context:
             func(*args, **kwargs)
+            return None
 
 
 class FixtureTestCase(FixtureMixin, TestCase):
diff --git a/ruff.toml b/ruff.toml
index 3b796847f5..de30d2c6e2 100644
--- a/ruff.toml
+++ b/ruff.toml
@@ -10,5 +10,7 @@ select = ["Q0", "F", "W", "E",
     "RET501",
     # flake8-return: implicit-return-value
     "RET502",
+    # flake8-return: implicit-return
+    "RET503",
 ]
 ignore = ["E501"]
-- 
GitLab