Skip to content

Commit fae4a77

Browse files
committed
Update ruff rules
1 parent c6eda9d commit fae4a77

File tree

10 files changed

+67
-43
lines changed

10 files changed

+67
-43
lines changed

flask_inputfilter/_input_filter.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,11 @@ cdef class InputFilter:
184184
dict[str, Any] validated_data
185185

186186
validated_data, errors = DataMixin.validate_with_conditions(
187-
self.fields, data, self.global_filters, self.global_validators, self.conditions
187+
self.fields,
188+
data,
189+
self.global_filters,
190+
self.global_validators,
191+
self.conditions,
188192
)
189193

190194
if errors:

flask_inputfilter/filters/string_slugify_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def apply(self, value: Any) -> Union[Optional[str], Any]:
3838

3939
value_without_accents = "".join(
4040
char
41-
for char in unicodedata.normalize(UnicodeFormEnum.NFD.value, value)
41+
for char in unicodedata.normalize(UnicodeFormEnum.NFD.value, value,)
4242
if unicodedata.category(char) != "Mn"
4343
)
4444

4545
value = unicodedata.normalize(
46-
UnicodeFormEnum.NFKD.value, value_without_accents
46+
UnicodeFormEnum.NFKD.value, value_without_accents,
4747
)
4848
value = value.encode("ascii", "ignore").decode("ascii")
4949

flask_inputfilter/filters/to_normalized_unicode_filter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def apply(self, value: Any) -> Union[str, Any]:
5959

6060
value_without_accents = "".join(
6161
char
62-
for char in unicodedata.normalize(UnicodeFormEnum.NFD.value, value)
62+
for char in unicodedata.normalize(UnicodeFormEnum.NFD.value, value,)
6363
if unicodedata.category(char) != "Mn"
6464
)
6565

66-
return unicodedata.normalize(self.form.value, value_without_accents)
66+
return unicodedata.normalize(self.form.value, value_without_accents,)

flask_inputfilter/input_filter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ def set_data(self, data: dict[str, Any]) -> None:
235235
data to be filtered and stored.
236236
"""
237237
self.data = DataMixin.filter_data(
238-
data, self.fields, self.global_filters
238+
data,
239+
self.fields,
240+
self.global_filters,
239241
)
240242

241243
def get_value(self, name: str) -> Any:

flask_inputfilter/mixins/data_mixin/data_mixin.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class DataMixin:
2121

2222
@staticmethod
2323
def has_unknown_fields(
24-
data: dict[str, Any], fields: dict[str, FieldModel]
24+
data: dict[str, Any],
25+
fields: dict[str, FieldModel],
2526
) -> bool:
2627
"""
2728
Check if data contains fields not defined in fields configuration. Uses
@@ -39,11 +40,6 @@ def has_unknown_fields(
3940
if not data and fields:
4041
return True
4142

42-
# Use set operations for faster lookup when there are many fields
43-
if len(fields) > LARGE_DATASET_THRESHOLD:
44-
field_set = set(fields.keys())
45-
return any(field_name not in field_set for field_name in data)
46-
# Use direct dict lookup for smaller field counts
4743
return any(field_name not in fields for field_name in data)
4844

4945
@staticmethod
@@ -120,7 +116,8 @@ def validate_with_conditions(
120116

121117
@staticmethod
122118
def merge_input_filters(
123-
target_filter: InputFilter, source_filter: InputFilter
119+
target_filter: InputFilter,
120+
source_filter: InputFilter,
124121
) -> None:
125122
"""
126123
Efficiently merge one InputFilter into another.
@@ -138,16 +135,21 @@ def merge_input_filters(
138135

139136
# Merge global filters (avoid duplicates by type)
140137
DataMixin._merge_component_list(
141-
target_filter.global_filters, source_filter.global_filters
138+
target_filter.global_filters,
139+
source_filter.global_filters,
142140
)
143141

144142
# Merge global validators (avoid duplicates by type)
145143
DataMixin._merge_component_list(
146-
target_filter.global_validators, source_filter.global_validators
144+
target_filter.global_validators,
145+
source_filter.global_validators,
147146
)
148147

149148
@staticmethod
150-
def _merge_component_list(target_list: list, source_list: list) -> None:
149+
def _merge_component_list(
150+
target_list: list,
151+
source_list: list,
152+
) -> None:
151153
"""
152154
Helper method to merge component lists avoiding duplicates by type.
153155

flask_inputfilter/mixins/external_api_mixin/external_api_mixin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ def call_external_api(
117117

118118
@staticmethod
119119
def replace_placeholders(
120-
value: str, validated_data: dict[str, Any]
120+
value: str,
121+
validated_data: dict[str, Any],
121122
) -> str:
122123
"""
123124
Replace all placeholders, marked with '{{ }}' in value with the
@@ -142,7 +143,8 @@ def replace_placeholders(
142143

143144
@staticmethod
144145
def replace_placeholders_in_params(
145-
params: dict, validated_data: dict[str, Any]
146+
params: dict,
147+
validated_data: dict[str, Any],
146148
) -> dict:
147149
"""
148150
Replace all placeholders in params with the corresponding values from

flask_inputfilter/mixins/validation_mixin/_validation_mixin.pyx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ cdef class ValidationMixin:
1313

1414
@staticmethod
1515
@cython.exceptval(check=False)
16-
cdef object apply_filters(list[BaseFilter] filters1, list[BaseFilter] filters2, object value):
16+
cdef object apply_filters(
17+
list[BaseFilter] filters1,
18+
list[BaseFilter] filters2,
19+
object value,
20+
):
1721
"""
1822
Apply filters to the field value.
1923
@@ -51,9 +55,9 @@ cdef class ValidationMixin:
5155

5256
@staticmethod
5357
cdef object apply_steps(
54-
list[BaseFilter | BaseValidator] steps,
55-
object fallback,
56-
object value
58+
list[BaseFilter | BaseValidator] steps,
59+
object fallback,
60+
object value,
5761
):
5862
"""
5963
Apply multiple filters and validators in a specific order.
@@ -105,7 +109,10 @@ cdef class ValidationMixin:
105109
return value
106110

107111
@staticmethod
108-
cdef void check_conditions(list[BaseCondition] conditions, dict[str, Any] validated_data) except *:
112+
cdef void check_conditions(
113+
list[BaseCondition] conditions,
114+
dict[str, Any] validated_data,
115+
) except *:
109116
"""
110117
Checks if all conditions are met.
111118
@@ -135,9 +142,9 @@ cdef class ValidationMixin:
135142

136143
@staticmethod
137144
cdef inline object check_for_required(
138-
str field_name,
139-
FieldModel field_info,
140-
object value,
145+
str field_name,
146+
FieldModel field_info,
147+
object value,
141148
):
142149
"""
143150
Determine the value of the field, considering the required and
@@ -177,10 +184,10 @@ cdef class ValidationMixin:
177184

178185
@staticmethod
179186
cdef object validate_field(
180-
list[BaseValidator] validators1,
181-
list[BaseValidator] validators2,
182-
object fallback,
183-
object value
187+
list[BaseValidator] validators1,
188+
list[BaseValidator] validators2,
189+
object fallback,
190+
object value
184191
):
185192
"""
186193
Validate the field value.
@@ -227,10 +234,10 @@ cdef class ValidationMixin:
227234

228235
@staticmethod
229236
cdef tuple validate_fields(
230-
dict[str, FieldModel] fields,
231-
dict[str, Any] data,
232-
list[BaseFilter] global_filters,
233-
list[BaseValidator] global_validators
237+
dict[str, FieldModel] fields,
238+
dict[str, Any] data,
239+
list[BaseFilter] global_filters,
240+
list[BaseValidator] global_validators
234241
):
235242
"""
236243
Validate multiple fields based on their configurations.
@@ -317,10 +324,10 @@ cdef class ValidationMixin:
317324

318325
@staticmethod
319326
cdef inline object get_field_value(
320-
str field_name,
321-
FieldModel field_info,
322-
dict[str, Any] data,
323-
dict[str, Any] validated_data
327+
str field_name,
328+
FieldModel field_info,
329+
dict[str, Any] data,
330+
dict[str, Any] validated_data
324331
):
325332
"""
326333
Retrieve the value of a field based on its configuration.

flask_inputfilter/mixins/validation_mixin/validation_mixin.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class ValidationMixin:
1515

1616
@staticmethod
1717
def apply_filters(
18-
filters1: list[BaseFilter], filters2: list[BaseFilter], value: Any
18+
filters1: list[BaseFilter],
19+
filters2: list[BaseFilter],
20+
value: Any,
1921
) -> Any:
2022
"""
2123
Apply filters to the field value.
@@ -132,7 +134,8 @@ def apply_steps(
132134

133135
@staticmethod
134136
def check_conditions(
135-
conditions: list[BaseCondition], validated_data: dict[str, Any]
137+
conditions: list[BaseCondition],
138+
validated_data: dict[str, Any],
136139
) -> None:
137140
"""
138141
Checks if all conditions are met.

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,15 @@ pyupgrade = [
141141
true
142142
]
143143

144+
[tool.ruff.lint.isort]
145+
force-single-line = false
146+
split-on-trailing-comma = true
147+
144148
[tool.ruff.format]
145149
quote-style = "double"
146150
indent-style = "space"
151+
skip-magic-trailing-comma = false
152+
line-ending = "lf"
147153

148154
[tool.docformatter]
149155
wrap-summaries = 79

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
pyx_files = Path("flask_inputfilter").rglob("*.pyx")
1212

13-
pyx_modules = [
14-
".".join(path.with_suffix("").parts) for path in pyx_files
15-
]
13+
pyx_modules = [".".join(path.with_suffix("").parts) for path in pyx_files]
1614

1715
ext_modules = cythonize(
1816
module_list=[

0 commit comments

Comments
 (0)