From 64e7c6869994f55416f429493977310ce68400e9 Mon Sep 17 00:00:00 2001 From: JuniorJPDJ Date: Sun, 6 Nov 2022 18:11:39 +0100 Subject: [PATCH] refactor(api): remove unnecessary or wrong `is` keyword usage --- api/funkwhale_api/audio/filters.py | 6 +++--- api/funkwhale_api/audio/views.py | 2 +- api/funkwhale_api/common/models.py | 2 +- api/funkwhale_api/federation/utils.py | 2 +- api/funkwhale_api/manage/views.py | 2 +- api/funkwhale_api/moderation/filters.py | 2 +- api/funkwhale_api/moderation/models.py | 2 +- api/funkwhale_api/music/filters.py | 5 +---- api/funkwhale_api/music/management/commands/import_files.py | 2 +- api/funkwhale_api/users/oauth/scopes.py | 2 +- api/tests/test_import_audio_file.py | 2 +- changes/changelog.d/is.enhancement | 1 + 12 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 changes/changelog.d/is.enhancement diff --git a/api/funkwhale_api/audio/filters.py b/api/funkwhale_api/audio/filters.py index 76f712a7c..2f3f5bb01 100644 --- a/api/funkwhale_api/audio/filters.py +++ b/api/funkwhale_api/audio/filters.py @@ -54,7 +54,7 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet): query = Q(actor__in=emitted_follows.values_list("target", flat=True)) - if value is True: + if value: return queryset.filter(query) else: return queryset.exclude(query) @@ -64,9 +64,9 @@ class ChannelFilter(moderation_filters.HiddenContentFilterSet): attributed_to=actors.get_service_actor(), actor__preferred_username__startswith="rssfeed-", ) - if value is True: + if value: queryset = queryset.filter(query) - if value is False: + else: queryset = queryset.exclude(query) return queryset diff --git a/api/funkwhale_api/audio/views.py b/api/funkwhale_api/audio/views.py index 6451b6264..314b2cb42 100644 --- a/api/funkwhale_api/audio/views.py +++ b/api/funkwhale_api/audio/views.py @@ -102,7 +102,7 @@ class ChannelViewSet( return serializers.ChannelSerializer elif self.action in ["update", "partial_update"]: return serializers.ChannelUpdateSerializer - elif self.action is "create": + elif self.action == "create": return serializers.ChannelCreateSerializer return serializers.ChannelSerializer diff --git a/api/funkwhale_api/common/models.py b/api/funkwhale_api/common/models.py index 9dd19c2ec..4f71c00aa 100644 --- a/api/funkwhale_api/common/models.py +++ b/api/funkwhale_api/common/models.py @@ -187,7 +187,7 @@ class AttachmentQuerySet(models.QuerySet): field_query = ~models.Q(**{field: None}) query = query | field_query if query else field_query - if include is False: + if not include: query = ~query return self.filter(query) diff --git a/api/funkwhale_api/federation/utils.py b/api/funkwhale_api/federation/utils.py index 766765dee..81ce02e95 100644 --- a/api/funkwhale_api/federation/utils.py +++ b/api/funkwhale_api/federation/utils.py @@ -249,7 +249,7 @@ FID_MODEL_LABELS = [ def get_object_by_fid(fid, local=None): - if local is True: + if local: parsed = urllib.parse.urlparse(fid) if parsed.netloc != settings.FEDERATION_HOSTNAME: raise ObjectDoesNotExist() diff --git a/api/funkwhale_api/manage/views.py b/api/funkwhale_api/manage/views.py index 292ac1fa1..627323003 100644 --- a/api/funkwhale_api/manage/views.py +++ b/api/funkwhale_api/manage/views.py @@ -537,7 +537,7 @@ class ManageReportViewSet( def perform_update(self, serializer): is_handled = serializer.instance.is_handled - if not is_handled and serializer.validated_data.get("is_handled") is True: + if not is_handled and serializer.validated_data.get("is_handled"): # report was resolved, we assign to the mod making the request serializer.save(assigned_to=self.request.user.actor) else: diff --git a/api/funkwhale_api/moderation/filters.py b/api/funkwhale_api/moderation/filters.py index 629ae685f..991b82479 100644 --- a/api/funkwhale_api/moderation/filters.py +++ b/api/funkwhale_api/moderation/filters.py @@ -64,7 +64,7 @@ class HiddenContentFilterSet(filters.FilterSet): config = self.__class__.Meta.hidden_content_fields_mapping final_query = get_filtered_content_query(config, user) - if value is True: + if value: return queryset.filter(final_query) else: return queryset.exclude(final_query) diff --git a/api/funkwhale_api/moderation/models.py b/api/funkwhale_api/moderation/models.py index 86086393c..447449410 100644 --- a/api/funkwhale_api/moderation/models.py +++ b/api/funkwhale_api/moderation/models.py @@ -226,7 +226,7 @@ class UserRequest(models.Model): @receiver(pre_save, sender=Report) def set_handled_date(sender, instance, **kwargs): - if instance.is_handled is True and not instance.handled_date: + if instance.is_handled and not instance.handled_date: instance.handled_date = timezone.now() elif not instance.is_handled: instance.handled_date = None diff --git a/api/funkwhale_api/music/filters.py b/api/funkwhale_api/music/filters.py index 22be0b7cc..3e152c497 100644 --- a/api/funkwhale_api/music/filters.py +++ b/api/funkwhale_api/music/filters.py @@ -135,10 +135,7 @@ class ArtistFilter( return queryset.playable_by(actor, value).distinct() def filter_has_albums(self, queryset, name, value): - if value is True: - return queryset.filter(albums__isnull=False) - else: - return queryset.filter(albums__isnull=True) + return queryset.filter(albums__isnull=not value) class TrackFilter( diff --git a/api/funkwhale_api/music/management/commands/import_files.py b/api/funkwhale_api/music/management/commands/import_files.py index cc56e07a9..afb83c8d0 100644 --- a/api/funkwhale_api/music/management/commands/import_files.py +++ b/api/funkwhale_api/music/management/commands/import_files.py @@ -355,7 +355,7 @@ class Command(BaseCommand): batch_duration = None self.stdout.write("Starting import of new files…") for i, entries in enumerate(batch(crawler, options["batch_size"])): - if options.get("update_cache", False) is True: + if options.get("update_cache", False): # check to see if the scan was cancelled if cache.get("fs-import:status") == "canceled": raise CommandError("Import cancelled") diff --git a/api/funkwhale_api/users/oauth/scopes.py b/api/funkwhale_api/users/oauth/scopes.py index 29d5ddae0..b3afd14ae 100644 --- a/api/funkwhale_api/users/oauth/scopes.py +++ b/api/funkwhale_api/users/oauth/scopes.py @@ -98,7 +98,7 @@ def get_from_permissions(**permissions): final = LOGGED_IN_SCOPES for permission_name, value in permissions.items(): - if value is False: + if not value: continue config = models.PERMISSIONS_CONFIGURATION[permission_name] final = final | config["scopes"] diff --git a/api/tests/test_import_audio_file.py b/api/tests/test_import_audio_file.py index 11b11fef5..87fdd4cf6 100644 --- a/api/tests/test_import_audio_file.py +++ b/api/tests/test_import_audio_file.py @@ -154,7 +154,7 @@ def test_import_files_in_place(factories, mocker, settings): interactive=False, ) upload = library.uploads.last() - assert bool(upload.audio_file) is False + assert not upload.audio_file mocked_process.assert_called_once_with(upload_id=upload.pk) diff --git a/changes/changelog.d/is.enhancement b/changes/changelog.d/is.enhancement new file mode 100644 index 000000000..410fb6b3e --- /dev/null +++ b/changes/changelog.d/is.enhancement @@ -0,0 +1 @@ +Remove unnecessary or wrong `is` keyword usage from backend