diff --git a/pyproject.toml b/pyproject.toml index 337e29e5b..4be0d75e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -186,6 +186,7 @@ line-ending = "lf" # https://docs.astral.sh/ruff/rules/ select = [ "E4", "E7", "E9", "F" ] extend-select = [ + "C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 "COM", # https://docs.astral.sh/ruff/rules/#flake8-commas-com "DJ", # https://docs.astral.sh/ruff/rules/#flake8-django-dj "EXE", # https://docs.astral.sh/ruff/rules/#flake8-executable-exe diff --git a/src/documents/filters.py b/src/documents/filters.py index 40ae8978b..455024ad8 100644 --- a/src/documents/filters.py +++ b/src/documents/filters.py @@ -734,7 +734,7 @@ class CustomFieldQueryParser: ) # Check if any of the requested IDs are missing. - missing_ids = set(value) - set(link.document_id for link in links) + missing_ids = set(value) - {link.document_id for link in links} if missing_ids: # The result should be an empty set in this case. return Q(id__in=[]) diff --git a/src/documents/search/_query.py b/src/documents/search/_query.py index 3584767bc..da841933e 100644 --- a/src/documents/search/_query.py +++ b/src/documents/search/_query.py @@ -240,7 +240,7 @@ def parse_user_query( DEFAULT_SEARCH_FIELDS, field_boosts=_FIELD_BOOSTS, # (prefix=True, distance=1, transposition_cost_one=True) — edit-distance fuzziness - fuzzy_fields={f: (True, 1, True) for f in DEFAULT_SEARCH_FIELDS}, + fuzzy_fields=dict.fromkeys(DEFAULT_SEARCH_FIELDS, (True, 1, True)), ) # 0.1 boost keeps fuzzy hits ranked below exact matches (intentional) clauses.append((tantivy.Occur.Should, tantivy.Query.boost_query(fuzzy, 0.1))) diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index dcb84b527..ff407b5ca 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -433,7 +433,7 @@ class OwnedObjectSerializer( return set() ctype = ContentType.objects.get_for_model(first_obj) - object_pks = list(obj.pk for obj in objects) + object_pks = [obj.pk for obj in objects] pk_type = type(first_obj.pk) def get_pks_for_permission_type(model): @@ -2056,13 +2056,12 @@ class BulkEditSerializer( for doc in docs: if "-" in doc: pages.append( - [ - x - for x in range( + list( + range( int(doc.split("-")[0]), int(doc.split("-")[1]) + 1, - ) - ], + ), + ), ) else: pages.append([int(doc)]) diff --git a/src/documents/tests/test_api_bulk_edit.py b/src/documents/tests/test_api_bulk_edit.py index cf447501c..7ad9c3457 100644 --- a/src/documents/tests/test_api_bulk_edit.py +++ b/src/documents/tests/test_api_bulk_edit.py @@ -1003,8 +1003,8 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase): for correspondent in response.data[field]: self.assertEqual(correspondent["document_count"], 0) self.assertCountEqual( - map(lambda c: c["id"], response.data[field]), - map(lambda c: c["id"], Entity.objects.values("id")), + (c["id"] for c in response.data[field]), + (c["id"] for c in Entity.objects.values("id")), ) def test_api_selection_data(self) -> None: diff --git a/src/documents/tests/test_api_profile.py b/src/documents/tests/test_api_profile.py index d642f52d8..5ed4a766b 100644 --- a/src/documents/tests/test_api_profile.py +++ b/src/documents/tests/test_api_profile.py @@ -18,8 +18,8 @@ class MockOpenIDProvider: def get_brands(self): default_servers = [ - dict(id="yahoo", name="Yahoo", openid_url="http://me.yahoo.com"), - dict(id="hyves", name="Hyves", openid_url="http://hyves.nl"), + {"id": "yahoo", "name": "Yahoo", "openid_url": "http://me.yahoo.com"}, + {"id": "hyves", "name": "Hyves", "openid_url": "http://hyves.nl"}, ] return default_servers diff --git a/src/documents/views.py b/src/documents/views.py index bc77dc5eb..f03aea7e2 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1478,13 +1478,12 @@ class DocumentViewSet( with get_date_parser() as date_parser: gen = date_parser.parse(doc.filename, doc.content) dates = sorted( - { - i - for i in itertools.islice( + set( + itertools.islice( gen, settings.NUMBER_OF_SUGGESTED_DATES, - ) - }, + ), + ), ) resp_data = { @@ -4135,7 +4134,7 @@ class UiSettingsView(GenericAPIView[Any]): user_resp["last_name"] = user.last_name # strip . - roles = map(lambda perm: re.sub(r"^\w+.", "", perm), user.get_all_permissions()) + roles = (re.sub(r"^\w+.", "", perm) for perm in user.get_all_permissions()) return Response( { "user": user_resp, diff --git a/src/paperless/tests/settings/test_db_cache.py b/src/paperless/tests/settings/test_db_cache.py index f190bb7d6..7559d4853 100644 --- a/src/paperless/tests/settings/test_db_cache.py +++ b/src/paperless/tests/settings/test_db_cache.py @@ -114,17 +114,17 @@ def test_cache_hit_when_enabled() -> None: assert settings.CACHALOT_TIMEOUT == 1 # Read a table to populate the cache - list(list(Tag.objects.values_list("id", flat=True))) + list(Tag.objects.values_list("id", flat=True)) # Invalidate the cache then read the database, there should be DB hit invalidate_db_cache() with CaptureQueriesContext(connection) as ctx: - list(list(Tag.objects.values_list("id", flat=True))) + list(Tag.objects.values_list("id", flat=True)) assert len(ctx) # Doing the same request again should hit the cache, not the DB with CaptureQueriesContext(connection) as ctx: - list(list(Tag.objects.values_list("id", flat=True))) + list(Tag.objects.values_list("id", flat=True)) assert not len(ctx) # Wait the end of TTL @@ -133,7 +133,7 @@ def test_cache_hit_when_enabled() -> None: # Read the DB again. The DB should be hit because the cache has expired with CaptureQueriesContext(connection) as ctx: - list(list(Tag.objects.values_list("id", flat=True))) + list(Tag.objects.values_list("id", flat=True)) assert len(ctx) # Invalidate the cache at the end of test @@ -149,7 +149,7 @@ def test_cache_is_disabled_by_default() -> None: # Read the table multiple times: the DB should always be hit without cache for _ in range(3): with CaptureQueriesContext(connection) as ctx: - list(list(Tag.objects.values_list("id", flat=True))) + list(Tag.objects.values_list("id", flat=True)) assert len(ctx) # Invalidate the cache at the end of test