Skip to content

Commit b9efcb9

Browse files
enable more rules (#244)
Signed-off-by: Ashwin Vaidya <[email protected]>
1 parent 17f3f18 commit b9efcb9

File tree

10 files changed

+21
-21
lines changed

10 files changed

+21
-21
lines changed

model_api/python/model_api/adapters/onnx_adapter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def embed_preprocessing(
164164
resize_fn = partial(RESIZE_TYPES[resize_mode], size=target_shape)
165165
preproc_funcs.append(resize_fn)
166166
input_transform = InputTransform(brg2rgb, mean, scale)
167-
preproc_funcs.append(input_transform.__call__)
168-
preproc_funcs.append(partial(change_layout, layout=layout))
167+
preproc_funcs.extend((input_transform.__call__, partial(change_layout, layout=layout)))
169168

170169
self.preprocessor = reduce(
171170
lambda f, g: lambda x: f(g(x)),

model_api/python/model_api/adapters/ovms_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def infer_async(self, dict_data, callback_data):
7777
# For models with single output ovmsclient returns ndarray with results,
7878
# so the dict must be created to correctly implement interface.
7979
if isinstance(raw_result, np.ndarray):
80-
output_name = list(self.metadata["outputs"].keys())[0]
80+
output_name = next(iter(self.metadata["outputs"].keys()))
8181
raw_result = {output_name: raw_result}
8282
self.callback_fn(raw_result, (lambda x: x, callback_data))
8383

model_api/python/model_api/models/anomaly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def postprocess(self, outputs: dict[str, np.ndarray], meta: dict[str, Any]) -> A
8787
pred_label: str | None = None
8888
pred_mask: np.ndarray | None = None
8989
pred_boxes: np.ndarray | None = None
90-
predictions = outputs[list(self.outputs)[0]]
90+
predictions = outputs[next(iter(self.outputs))]
9191

9292
if len(predictions.shape) == 1:
9393
pred_score = predictions

model_api/python/model_api/models/classification.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import copy
99
import json
10+
from itertools import starmap
1011
from pathlib import Path
1112
from typing import TYPE_CHECKING
1213

@@ -303,7 +304,7 @@ def get_multilabel_predictions(self, logits: np.ndarray) -> list[Label]:
303304
scores.append(logits[i])
304305
labels = [self.labels[i] if self.labels else "" for i in indices]
305306

306-
return [Label(*data) for data in zip(indices, labels, scores)]
307+
return list(starmap(Label, zip(indices, labels, scores)))
307308

308309
def get_multiclass_predictions(self, outputs: dict) -> list[Label]:
309310
if self.embedded_topk:
@@ -314,7 +315,7 @@ def get_multiclass_predictions(self, outputs: dict) -> list[Label]:
314315
scoresTensor = softmax(outputs[self.out_layer_names[0]][0])
315316
indicesTensor = [int(np.argmax(scoresTensor))]
316317
labels = [self.labels[i] if self.labels else "" for i in indicesTensor]
317-
return [Label(*data) for data in zip(indicesTensor, labels, scoresTensor)]
318+
return list(starmap(Label, zip(indicesTensor, labels, scoresTensor)))
318319

319320

320321
def addOrFindSoftmaxAndTopkOutputs(inference_adapter: InferenceAdapter, topk: int, output_raw_scores: bool) -> None:

model_api/python/model_api/models/instance_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def postprocess(self, outputs: dict, meta: dict) -> InstanceSegmentationResult:
221221
labels=labels,
222222
scores=scores,
223223
masks=_masks,
224-
label_names=label_names if label_names else None,
224+
label_names=label_names or None,
225225
saliency_map=_average_and_normalize(saliency_maps),
226226
feature_vector=outputs.get(_feature_vector_name, np.ndarray(0)),
227227
)

model_api/python/model_api/models/sam_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(
3232
preload: bool = False,
3333
):
3434
super().__init__(inference_adapter, configuration, preload)
35-
self.output_name: str = list(self.outputs.keys())[0]
35+
self.output_name: str = next(iter(self.outputs.keys()))
3636
self.resize_type: str
3737
self.image_size: int
3838

model_api/python/model_api/models/visual_prompting.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,9 @@ def _predict_masks(
484484
elif i == 1:
485485
# Cascaded Post-refinement-1
486486
mask_input, masks, _ = _decide_masks(
487-
masks,
488-
logits,
489-
scores,
487+
masks, # noqa: F821 masks are set in the first iteration
488+
logits, # noqa: F821 masks are set in the first iteration
489+
scores, # noqa: F821 masks are set in the first iteration
490490
is_single=True,
491491
)
492492
if masks.sum() == 0:
@@ -498,8 +498,8 @@ def _predict_masks(
498498
# Cascaded Post-refinement-2
499499
mask_input, masks, _ = _decide_masks(
500500
masks,
501-
logits,
502-
scores,
501+
logits, # noqa: F821 masks are set in the first iteration
502+
scores, # noqa: F821 masks are set in the first iteration
503503
)
504504
if masks.sum() == 0:
505505
return {"upscaled_masks": masks}

model_api/python/model_api/tilers/instance_segmentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _merge_results(self, results, shape) -> InstanceSegmentationResult:
132132
labels=labels.squeeze(),
133133
scores=scores.squeeze(),
134134
masks=resized_masks,
135-
label_names=label_names if label_names else None,
135+
label_names=label_names or None,
136136
saliency_map=saliency_map,
137137
feature_vector=merged_vector,
138138
)

model_api/python/model_api/tilers/tiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
class Tiler(abc.ABC):
15-
EXECUTION_MODES = ["async", "sync"]
15+
EXECUTION_MODES = ("async", "sync")
1616
"""
1717
An abstract tiler
1818

model_api/python/pyproject.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ preview = true
9191

9292
# Enable rules
9393
lint.select = [
94-
# "F", # Pyflakes (`F`)
94+
"F", # Pyflakes (`F`)
9595
"E", # pycodestyle error (`E`)
9696
"W", # pycodestyle warning (`W`)
9797
"C90", # mccabe (`C90`)
@@ -127,18 +127,18 @@ lint.select = [
127127
# "ARG", # flake8-unsused-arguments (`ARG`)
128128
"PTH", # flake8-use-pathlib (`PTH`)
129129
# "TD", # flake8-todos (`TD`)
130-
# "FIX", # flake8-fixme (`FIX`)
130+
"FIX", # flake8-fixme (`FIX`)
131131
"ERA", # eradicate (`ERA`)
132132
"PD", # pandas-vet (`PD`)
133133
"PGH", # pygrep-hooks (`PGH`)
134134
# "PL", # pylint (`PL`)
135135
# "TRY", # tryceratos (`TRY`)
136-
# "FLY", # flynt (`FLY`)
136+
"FLY", # flynt (`FLY`)
137137
"NPY", # NumPy-specific rules (`NPY`)
138138
# "PERF", # Perflint (`PERF`)
139-
# "RUF", # Ruff-specific rules (`RUF`)
140-
# "FURB", # refurb (`FURB`) - ERROR: Unknown rule selector: `FURB`
141-
# "LOG", # flake8-logging (`LOG`) - ERROR: Unknown rule selector: `LOG`
139+
"RUF", # Ruff-specific rules (`RUF`)
140+
"FURB", # refurb (`FURB`) - ERROR: Unknown rule selector: `FURB`
141+
"LOG", # flake8-logging (`LOG`) - ERROR: Unknown rule selector: `LOG`
142142
]
143143

144144
lint.ignore = [

0 commit comments

Comments
 (0)