Skip to content

Commit 1ec10b6

Browse files
committed
linting
1 parent 38ebf3e commit 1ec10b6

File tree

7 files changed

+31
-29
lines changed

7 files changed

+31
-29
lines changed

backend/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ lint.select = [
148148
lint.ignore = [
149149
# DoNotAssignLambda
150150
"E731",
151+
# Function complexity
152+
"C901",
151153
]
152154

153155
[tool.ruff.lint.isort]

backend/src/kitconcept/solr/services/solr_highlighting_utils.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ class SolrHighlightingUtils:
55

66
def __init__(self, solr_config):
77
highlightingFields = solr_config.config.get("highlightingFields", [])
8-
self.fields = list(map(lambda field: field["field"], highlightingFields))
8+
self.fields = [field["field"] for field in highlightingFields]
99
self.enabled = len(self.fields) > 0
10-
self.propByField = dict(
11-
map(
12-
lambda field: (field["field"], field["prop"]),
13-
highlightingFields,
14-
)
15-
)
10+
self.propByField = {
11+
field["field"]: field["prop"] for field in highlightingFields
12+
}
1613

1714
def enhance_items(self, items: list, highlighting: dict):
1815
if self.enabled:

backend/src/kitconcept/solr/services/solr_utils_extra.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ def query_list(self):
7676
keys = set(condition.keys())
7777
if not keys.issubset({"in"}):
7878
raise RuntimeError(
79-
f"invalid keys in options for condition 'string', supported: 'in' [{keys}]"
79+
"invalid keys in options for condition 'string', "
80+
f"supported: 'in' [{keys}]"
8081
)
8182
if "in" in condition:
8283
if type(condition["in"]) is not list:
8384
raise RuntimeError(
84-
f"invalid type for condition 'string' [{type(condition['in'])}]"
85+
"invalid type for condition 'string' "
86+
f"[{type(condition['in'])}]"
8587
)
8688
if len(condition["in"]) == 0:
8789
# Empty list, ignore
@@ -90,12 +92,7 @@ def query_list(self):
9092
result += (
9193
"("
9294
+ " OR ".join(
93-
list(
94-
map(
95-
lambda term: replace_reserved(term),
96-
condition["in"],
97-
)
98-
)
95+
[replace_reserved(term) for term in condition["in"]]
9996
)
10097
+ ")"
10198
)

backend/src/kitconcept/solr/services/suggest.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ def query_suggest(self, query):
4040
term = f"({escape(replace_reserved(query))})" if query else "*"
4141
d = {
4242
"q": (
43-
f"+suggest:{term}^10 OR +suggest_ngram:{term} OR +searchwords:{term}^1000 OR +suggest_searchwords_ngram:{term}"
43+
f"+suggest:{term}^10 OR +suggest_ngram:{term} "
44+
f"OR +searchwords:{term}^1000 OR +suggest_searchwords_ngram:{term}"
4445
),
4546
"fq": [
4647
security_filter(),
4748
"-showinsearch:False",
48-
"-portal_type:Image -portal_type:Glossary -portal_type:FAQ -portal_type:(FAQ Item) -portal_type:(FAQ Category) -portal_type:Link",
49+
(
50+
"-portal_type:Image -portal_type:Glossary -portal_type:FAQ "
51+
"-portal_type:(FAQ Item) -portal_type:(FAQ Category) "
52+
"-portal_type:Link"
53+
),
4954
],
5055
"defType": "lucene",
5156
}
@@ -55,7 +60,7 @@ def query_suggest(self, query):
5560

5661
d["fq"] = " AND ".join(d["fq"])
5762
querystring = urllib.parse.urlencode(d)
58-
url = "{}/{}".format(connection.solrBase, "suggest?%s" % querystring)
63+
url = "{}/{}".format(connection.solrBase, f"suggest?{querystring}")
5964
try:
6065
res = connection.doGet(url, {"Accept": "application/json"})
6166
data = json.loads(res.read())

backend/tests/services/extra_conditions/test_extra_conditions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import json
33
import pytest
4+
from typing import ClassVar
45

56

67
def encoded(o):
@@ -124,7 +125,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
124125

125126

126127
class TestExtraConditionsDateGe(TestEndpointCustom):
127-
extra_conditions = [
128+
extra_conditions: ClassVar[list] = [
128129
[
129130
"start",
130131
"date-range",
@@ -167,7 +168,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
167168

168169

169170
class TestExtraConditionsDateLe(TestEndpointCustom):
170-
extra_conditions = [
171+
extra_conditions: ClassVar[list] = [
171172
[
172173
"start",
173174
"date-range",
@@ -210,7 +211,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
210211

211212

212213
class TestExtraConditionsDateGeLe(TestEndpointCustom):
213-
extra_conditions = [
214+
extra_conditions: ClassVar[list] = [
214215
[
215216
"start",
216217
"date-range",
@@ -253,7 +254,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
253254

254255

255256
class TestExtraConditionsDateGrLs(TestEndpointCustom):
256-
extra_conditions = [
257+
extra_conditions: ClassVar[list] = [
257258
[
258259
"start",
259260
"date-range",
@@ -296,7 +297,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
296297

297298

298299
class TestExtraConditionsStringInSingleTerm(TestEndpointCustom):
299-
extra_conditions = [
300+
extra_conditions: ClassVar[list] = [
300301
[
301302
"searchwords",
302303
"string",
@@ -327,7 +328,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
327328

328329

329330
class TestExtraConditionsStringInSingleTerm2(TestEndpointCustom):
330-
extra_conditions = [
331+
extra_conditions: ClassVar[list] = [
331332
[
332333
"searchwords",
333334
"string",
@@ -358,7 +359,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
358359

359360

360361
class TestExtraConditionsStringInMultipleTerms(TestEndpointCustom):
361-
extra_conditions = [
362+
extra_conditions: ClassVar[list] = [
362363
[
363364
"searchwords",
364365
"string",
@@ -389,7 +390,7 @@ def test_paths(self, all_path_string, path: str, expected: bool):
389390

390391

391392
class TestExtraConditionsStringInNoTerms(TestEndpointCustom):
392-
extra_conditions = [
393+
extra_conditions: ClassVar[list] = [
393394
[
394395
"searchwords",
395396
"string",

backend/tests/services/highlighting/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from typing import List
21

32
import pytest
43

54

65
@pytest.fixture
7-
def contents() -> List:
6+
def contents() -> list:
87
"""Content to be created."""
98
return [
109
{

backend/tests/services/suggest/test_suggest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
import urllib.parse
3+
from typing import ClassVar
34

45

56
class TestSuggestDefault:
@@ -40,7 +41,7 @@ def func(data, index: int) -> dict:
4041

4142
class TestSuggestDefaultBaseSearch(TestSuggestDefault):
4243
url = "/@solr-suggest?query=chomsky"
43-
expected_result = [
44+
expected_result: ClassVar[list] = [
4445
{
4546
"@id": "http://localhost:59793/plone/mydocument",
4647
"@type": "Document",

0 commit comments

Comments
 (0)