mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-28 13:37:32 +00:00
Chore: enable flake8-comprehensions (C4) ruff rules
C4 is part of ruff 0.16's expanded default rule set and is almost entirely autofixable, making it a low-risk first step towards adopting the new defaults.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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=[])
|
||||
|
||||
@@ -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)))
|
||||
|
||||
@@ -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)])
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 <app_label>.
|
||||
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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user