From 65b3a4a1f9df0f3659f600b0ebf27abba76fa84e Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Thu, 31 Oct 2024 16:29:22 +0100 Subject: [PATCH 1/4] enable pycodestyle Signed-off-by: Ashwin Vaidya --- .../model_api/adapters/inference_adapter.py | 2 +- .../model_api/adapters/openvino_adapter.py | 4 +-- model_api/python/model_api/adapters/utils.py | 2 +- .../model_api/models/action_classification.py | 5 +++- .../python/model_api/models/classification.py | 9 ++++-- .../python/model_api/models/image_model.py | 5 +++- model_api/python/model_api/models/model.py | 16 ++++++---- .../python/model_api/models/segmentation.py | 5 +++- model_api/python/model_api/models/utils.py | 21 +++++++++---- .../model_api/models/visual_prompting.py | 30 ++++++++++++------- model_api/python/model_api/models/yolo.py | 10 +++++-- model_api/python/pyproject.toml | 2 +- 12 files changed, 77 insertions(+), 34 deletions(-) diff --git a/model_api/python/model_api/adapters/inference_adapter.py b/model_api/python/model_api/adapters/inference_adapter.py index 42b25649..464092a0 100644 --- a/model_api/python/model_api/adapters/inference_adapter.py +++ b/model_api/python/model_api/adapters/inference_adapter.py @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from dataclasses import dataclass, field -from typing import Any, Dict, List, Set, Tuple +from typing import Any @dataclass diff --git a/model_api/python/model_api/adapters/openvino_adapter.py b/model_api/python/model_api/adapters/openvino_adapter.py index 0fa536cb..e48e80e7 100644 --- a/model_api/python/model_api/adapters/openvino_adapter.py +++ b/model_api/python/model_api/adapters/openvino_adapter.py @@ -339,9 +339,9 @@ def embed_preprocessing( ppp = PrePostProcessor(self.model) # Change the input type to the 8-bit image - if dtype == int: + if dtype is int: ppp.input(input_idx).tensor().set_element_type(Type.u8) - elif dtype == float: + elif dtype is float: ppp.input(input_idx).tensor().set_element_type(Type.f32) ppp.input(input_idx).tensor().set_layout(ov.Layout("NHWC")).set_color_format( diff --git a/model_api/python/model_api/adapters/utils.py b/model_api/python/model_api/adapters/utils.py index 96f92af2..149d76f1 100644 --- a/model_api/python/model_api/adapters/utils.py +++ b/model_api/python/model_api/adapters/utils.py @@ -7,7 +7,7 @@ import math from functools import partial -from typing import Callable, Optional +from typing import Callable import cv2 import numpy as np diff --git a/model_api/python/model_api/models/action_classification.py b/model_api/python/model_api/models/action_classification.py index e757aa9b..bfa12d6d 100644 --- a/model_api/python/model_api/models/action_classification.py +++ b/model_api/python/model_api/models/action_classification.py @@ -99,7 +99,10 @@ def parameters(cls) -> dict[str, Any]: description="Path to file with labels. Overrides the labels, if they sets via 'labels' parameter", ), "mean_values": ListValue( - description="Normalization values, which will be subtracted from image channels for image-input layer during preprocessing", + description=( + "Normalization values, which will be subtracted from image channels " + "for image-input layer during preprocessing" + ), default_value=[], ), "pad_value": NumericalValue( diff --git a/model_api/python/model_api/models/classification.py b/model_api/python/model_api/models/classification.py index 77bd56a7..470f80cd 100644 --- a/model_api/python/model_api/models/classification.py +++ b/model_api/python/model_api/models/classification.py @@ -374,7 +374,11 @@ def resolve_labels(self, predictions): """ def get_predecessors(lbl, candidates): - """Returns all the predecessors of the input label or an empty list if one of the predecessors is not a candidate.""" + """Return all predecessors. + + Returns all the predecessors of the input label or an empty list if one of the predecessors is not a + candidate. + """ predecessors = [] last_parent = self.label_tree.get_parent(lbl) @@ -517,7 +521,8 @@ def _resolve_exclusive_labels( For labels in `label_to_probability` sets labels that are most likely (maximum probability) in their exclusive group to 1.0 and other (non-max) labels to probability 0. """ - # actual exclusive group selection should happen when extracting initial probs (apply argmax to exclusive groups) + # actual exclusive group selection should happen when extracting initial probs + # (apply argmax to exclusive groups) hard_classification = {} for label, probability in label_to_probability.items(): hard_classification[label] = float(probability > 0.0) diff --git a/model_api/python/model_api/models/image_model.py b/model_api/python/model_api/models/image_model.py index 25780c3d..9e32f15c 100644 --- a/model_api/python/model_api/models/image_model.py +++ b/model_api/python/model_api/models/image_model.py @@ -90,7 +90,10 @@ def parameters(cls): default_value=False, ), "mean_values": ListValue( - description="Normalization values, which will be subtracted from image channels for image-input layer during preprocessing", + description=( + "Normalization values, which will be subtracted from image " + "channels for image-input layer during preprocessing" + ), default_value=[], ), "orig_height": NumericalValue( diff --git a/model_api/python/model_api/models/model.py b/model_api/python/model_api/models/model.py index 3d2f4a1e..5515dfa8 100644 --- a/model_api/python/model_api/models/model.py +++ b/model_api/python/model_api/models/model.py @@ -5,7 +5,6 @@ import logging as log import re -from abc import ABC from contextlib import contextmanager from model_api.adapters.inference_adapter import InferenceAdapter @@ -135,9 +134,11 @@ def create_model( Args: model (str): model name from OpenVINO Model Zoo, path to model, OVMS URL - configuration (:obj:`dict`, optional): dictionary of model config with model properties, for example confidence_threshold, labels + configuration (:obj:`dict`, optional): dictionary of model config with model properties, for example + confidence_threshold, labels model_type (:obj:`str`, optional): name of model wrapper to create (e.g. "ssd") - preload (:obj:`bool`, optional): whether to call load_model(). Can be set to false to reshape model before loading + preload (:obj:`bool`, optional): whether to call load_model(). Can be set to false to reshape model before + loading. core (optional): openvino.Core instance, passed to OpenvinoAdapter weights_path (:obj:`str`, optional): path to .bin file with model weights adaptor_parameters (:obj:`dict`, optional): parameters of ModelAdaptor @@ -147,7 +148,8 @@ def create_model( max_num_requests (:obj:`int`, optional): number of infer requests for asynchronous inference precision (:obj:`str`, optional): inference precision (e.g. "FP16") download_dir (:obj:`str`, optional): directory where to store downloaded models - cache_dir (:obj:`str`, optional): directory where to store compiled models to reduce the load time before the inference + cache_dir (:obj:`str`, optional): directory where to store compiled models to reduce the load time before + the inference. Returns: Model object @@ -482,11 +484,13 @@ def log_layers_info(self): """Prints the shape, precision and layout for all model inputs/outputs.""" for name, metadata in self.inputs.items(): self.logger.info( - f"\tInput layer: {name}, shape: {metadata.shape}, precision: {metadata.precision}, layout: {metadata.layout}", + f"\tInput layer: {name}, shape: {metadata.shape}, " + f"precision: {metadata.precision}, layout: {metadata.layout}", ) for name, metadata in self.outputs.items(): self.logger.info( - f"\tOutput layer: {name}, shape: {metadata.shape}, precision: {metadata.precision}, layout: {metadata.layout}", + f"\tOutput layer: {name}, shape: {metadata.shape}, " + f"precision: {metadata.precision}, layout: {metadata.layout}", ) def save(self, xml_path, bin_path="", version="UNSPECIFIED"): diff --git a/model_api/python/model_api/models/segmentation.py b/model_api/python/model_api/models/segmentation.py index 3faf030b..ce7356a5 100644 --- a/model_api/python/model_api/models/segmentation.py +++ b/model_api/python/model_api/models/segmentation.py @@ -99,7 +99,10 @@ def parameters(cls): ), "soft_threshold": NumericalValue( value_type=float, - description="Probability threshold value for bounding box filtering. inf value means no blurring and no soft_threshold", + description=( + "Probability threshold value for bounding box filtering. " + "inf value means no blurring and no soft_threshold" + ), default_value=float("-inf"), ), "return_soft_prediction": BooleanValue( diff --git a/model_api/python/model_api/models/utils.py b/model_api/python/model_api/models/utils.py index 030b6f08..88fa22ab 100644 --- a/model_api/python/model_api/models/utils.py +++ b/model_api/python/model_api/models/utils.py @@ -47,7 +47,9 @@ class ClassificationResult( def __str__(self): labels = ", ".join(f"{idx} ({label}): {confidence:.3f}" for idx, label, confidence in self.top_labels) return ( - f"{labels}, [{','.join(str(i) for i in self.saliency_map.shape)}], [{','.join(str(i) for i in self.feature_vector.shape)}], " + f"{labels}, " + f"[{','.join(str(i) for i in self.saliency_map.shape)}], " + f"[{','.join(str(i) for i in self.feature_vector.shape)}], " f"[{','.join(str(i) for i in self.raw_scores.shape)}]" ) @@ -76,7 +78,9 @@ def __str__(self): obj_str = "; ".join(str(obj) for obj in self.objects) if obj_str: obj_str += "; " - return f"{obj_str}[{','.join(str(i) for i in self.saliency_map.shape)}]; [{','.join(str(i) for i in self.feature_vector.shape)}]" + saliency_map_shape = ",".join(str(i) for i in self.saliency_map.shape) + feature_vector_shape = ",".join(str(i) for i in self.feature_vector.shape) + return f"{obj_str}[{saliency_map_shape}]; [{feature_vector_shape}]" class SegmentedObject(Detection): @@ -194,14 +198,18 @@ class DetectedKeypoints(NamedTuple): scores: np.ndarray def __str__(self): - return f"keypoints: {self.keypoints.shape}, keypoints_x_sum: {np.sum(self.keypoints[:, :1]):.3f}, scores: {self.scores.shape}" + return ( + f"keypoints: {self.keypoints.shape}, " + f"keypoints_x_sum: {np.sum(self.keypoints[:, :1]):.3f}, " + f"scores: {self.scores.shape}" + ) def add_rotated_rects(segmented_objects): objects_with_rects = [] for segmented_object in segmented_objects: mask = segmented_object.mask.astype(np.uint8) - contours, hierarchies = cv2.findContours( + contours, _ = cv2.findContours( mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE, @@ -269,7 +277,10 @@ def __str__(self): for i, count in enumerate(outHist): if count > 0: hist += f"{i}: {count[0] / self.resultImage.size:.3f}, " - return f"{hist}[{','.join(str(i) for i in self.soft_prediction.shape)}], [{','.join(str(i) for i in self.saliency_map.shape)}], [{','.join(str(i) for i in self.feature_vector.shape)}]" + soft_pred_shape = ",".join(str(i) for i in self.soft_prediction.shape) + saliency_map_shape = ",".join(str(i) for i in self.saliency_map.shape) + feature_vector_shape = ",".join(str(i) for i in self.feature_vector.shape) + return f"{hist}[{soft_pred_shape}], " f"[{saliency_map_shape}], " f"[{feature_vector_shape}]" class DetectionWithLandmarks(Detection): diff --git a/model_api/python/model_api/models/visual_prompting.py b/model_api/python/model_api/models/visual_prompting.py index a9b83b9b..845d6126 100644 --- a/model_api/python/model_api/models/visual_prompting.py +++ b/model_api/python/model_api/models/visual_prompting.py @@ -143,7 +143,8 @@ def __init__( encoder_model (SAMImageEncoder): initialized decoder wrapper decoder_model (SAMDecoder): initialized encoder wrapper reference_features (VisualPromptingFeatures | None, optional): Previously generated reference features. - Once the features are passed, one can skip learn() method, and start predicting masks right away. Defaults to None. + Once the features are passed, one can skip learn() method, and start predicting masks right away. + Defaults to None. threshold (float, optional): Threshold to match vs reference features on infer(). Greater value means a stricter matching. Defaults to 0.65. """ @@ -213,7 +214,8 @@ def learn( reset_features (bool, optional): Forces learning from scratch. Defaults to False. Returns: - tuple[VisualPromptingFeatures, np.ndarray]: return values are the updated VPT reference features and reference masks. + tuple[VisualPromptingFeatures, np.ndarray]: return values are the updated VPT reference features and + reference masks. The shape of the reference mask is N_labels x H x W, where H and W are the same as in the input image. """ if boxes is None and points is None and polygons is None: @@ -317,26 +319,32 @@ def infer( Args: image (np.ndarray): HWC-shaped image - reference_features (VisualPromptingFeatures | None, optional): Reference features object obtained during previous learn() calls. - If not passed, object internal state is used, which reflects the last learn() call. Defaults to None. - apply_masks_refinement (bool, optional): Flag controlling additional refinement stage on inference. Once enabled, decoder will - be launched 2 extra times to refine the masks obtained with the first decoder call. Defaults to True. + reference_features (VisualPromptingFeatures | None, optional): Reference features object obtained during + previous learn() calls. If not passed, object internal state is used, which reflects the last learn() + call. Defaults to None. + apply_masks_refinement (bool, optional): Flag controlling additional refinement stage on inference. + Once enabled, decoder will be launched 2 extra times to refine the masks obtained with the first decoder + call. Defaults to True. Returns: - ZSLVisualPromptingResult: Mapping label -> predicted mask. Each mask object contains a list of binary masks, and a list of - related prompts. Each binary mask corresponds to one prompt point. Class mask can be obtained by applying OR operation to all - mask corresponding to one label. + ZSLVisualPromptingResult: Mapping label -> predicted mask. Each mask object contains a list of binary masks, + and a list of related prompts. Each binary mask corresponds to one prompt point. Class mask can be + obtained by applying OR operation to all mask corresponding to one label. """ if reference_features is None: if self._reference_features is None: raise RuntimeError( - "Reference features are not defined. This parameter can be passed via SAMLearnableVisualPrompter constructor, or as an argument of infer() method", + ( + "Reference features are not defined. This parameter can be passed via " + "SAMLearnableVisualPrompter constructor, or as an argument of infer() method" + ), ) reference_feats = self._reference_features if self._used_indices is None: raise RuntimeError( - "Used indices are not defined. This parameter can be passed via SAMLearnableVisualPrompter constructor, or as an argument of infer() method", + "Used indices are not defined. This parameter can be passed via " + "SAMLearnableVisualPrompter constructor, or as an argument of infer() method" ) used_idx = self._used_indices else: diff --git a/model_api/python/model_api/models/yolo.py b/model_api/python/model_api/models/yolo.py index 7a4dd12c..37057905 100644 --- a/model_api/python/model_api/models/yolo.py +++ b/model_api/python/model_api/models/yolo.py @@ -630,7 +630,10 @@ def _get_outputs(self): ) if self.outputs[bboxes_blob_name].shape[1] != self.outputs[scores_blob_name].shape[2]: self.raise_error( - f"Expected the same dimension for boxes and scores, but got {self.outputs[bboxes_blob_name].shape[1]} and {self.outputs[scores_blob_name].shape[2]}", + ( + f"Expected the same dimension for boxes and scores, but got " + f"{self.outputs[bboxes_blob_name].shape[1]} and {self.outputs[scores_blob_name].shape[2]}" + ), ) return bboxes_blob_name, scores_blob_name, indices_blob_name @@ -745,7 +748,10 @@ def parameters(cls): parameters.update( { "agnostic_nms": BooleanValue( - description="If True, the model is agnostic to the number of classes, and all classes are considered as one", + description=( + "If True, the model is agnostic to the number of classes, " + "and all classes are considered as one" + ), default_value=False, ), "iou_threshold": NumericalValue( diff --git a/model_api/python/pyproject.toml b/model_api/python/pyproject.toml index d6a1377e..349c43d2 100644 --- a/model_api/python/pyproject.toml +++ b/model_api/python/pyproject.toml @@ -91,7 +91,7 @@ preview = true # Enable rules lint.select = [ # "F", # Pyflakes (`F`) - # "E", # pycodestyle error (`E`) + "E", # pycodestyle error (`E`) # "W", # pycodestyle warning (`W`) # "C90", # mccabe (`C90`) "I", # isort (`I`) From fe65ede4b6202a52dce3dedb458616a3195d4313 Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Thu, 31 Oct 2024 16:40:16 +0100 Subject: [PATCH 2/4] enable more rules Signed-off-by: Ashwin Vaidya --- .../model_api/adapters/openvino_adapter.py | 4 ++-- .../python/model_api/adapters/ovms_adapter.py | 2 +- model_api/python/model_api/adapters/utils.py | 2 +- .../model_api/models/instance_segmentation.py | 5 ++--- model_api/python/model_api/models/types.py | 15 +++++++------- model_api/python/model_api/models/yolo.py | 2 +- .../model_api/pipelines/async_pipeline.py | 2 +- model_api/python/pyproject.toml | 20 +++++++++---------- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/model_api/python/model_api/adapters/openvino_adapter.py b/model_api/python/model_api/adapters/openvino_adapter.py index e48e80e7..3fcb93c8 100644 --- a/model_api/python/model_api/adapters/openvino_adapter.py +++ b/model_api/python/model_api/adapters/openvino_adapter.py @@ -133,7 +133,7 @@ def __init__( self.is_onnx_file = False self.onnx_metadata = {} - if isinstance(self.model_path, (str, Path)): + if isinstance(self.model_path, str | Path): if Path(self.model_path).suffix == ".onnx" and weights_path: log.warning( 'For model in ONNX format should set only "model_path" parameter.' @@ -301,7 +301,7 @@ def await_any(self) -> None: def _get_meta_from_ngraph(self, layers_info): for node in self.model.get_ordered_ops(): layer_name = node.get_friendly_name() - if layer_name not in layers_info.keys(): + if layer_name not in layers_info: continue layers_info[layer_name].meta = node.get_attributes() layers_info[layer_name].type = node.get_type_name() diff --git a/model_api/python/model_api/adapters/ovms_adapter.py b/model_api/python/model_api/adapters/ovms_adapter.py index 2056b45b..78935233 100644 --- a/model_api/python/model_api/adapters/ovms_adapter.py +++ b/model_api/python/model_api/adapters/ovms_adapter.py @@ -185,7 +185,7 @@ def _verify_model_available(client, model_name, model_version): def _prepare_inputs(dict_data, inputs_meta): inputs = {} for input_name, input_data in dict_data.items(): - if input_name not in inputs_meta.keys(): + if input_name not in inputs_meta: raise ValueError("Input data does not match model inputs") input_info = inputs_meta[input_name] model_precision = _tf2np_precision[input_info["dtype"]] diff --git a/model_api/python/model_api/adapters/utils.py b/model_api/python/model_api/adapters/utils.py index 149d76f1..b8c7d867 100644 --- a/model_api/python/model_api/adapters/utils.py +++ b/model_api/python/model_api/adapters/utils.py @@ -6,8 +6,8 @@ from __future__ import annotations # TODO: remove when Python3.9 support is dropped import math +from collections.abc import Callable from functools import partial -from typing import Callable import cv2 import numpy as np diff --git a/model_api/python/model_api/models/instance_segmentation.py b/model_api/python/model_api/models/instance_segmentation.py index 7fd4a982..7fc438b2 100644 --- a/model_api/python/model_api/models/instance_segmentation.py +++ b/model_api/python/model_api/models/instance_segmentation.py @@ -207,9 +207,8 @@ def postprocess(self, outputs, meta): output_mask, ), ) - if has_feature_vector_name: - if confidence > self.confidence_threshold: - saliency_maps[cls - 1].append(resized_mask) + if has_feature_vector_name and confidence > self.confidence_threshold: + saliency_maps[cls - 1].append(resized_mask) return InstanceSegmentationResult( objects, _average_and_normalize(saliency_maps), diff --git a/model_api/python/model_api/models/types.py b/model_api/python/model_api/models/types.py index 77e40d85..0784baac 100644 --- a/model_api/python/model_api/models/types.py +++ b/model_api/python/model_api/models/types.py @@ -69,13 +69,12 @@ def validate(self, value): ), ) return errors - if len(self.choices): - if value not in self.choices: - errors.append( - ConfigurableValueError( - f"Incorrect value {value}: out of allowable list - {self.choices}", - ), - ) + if len(self.choices) and value not in self.choices: + errors.append( + ConfigurableValueError( + f"Incorrect value {value}: out of allowable list - {self.choices}", + ), + ) if self.min is not None and value < self.min: errors.append( ConfigurableValueError( @@ -188,7 +187,7 @@ def validate(self, value): errors = super().validate(value) if not value: return errors - if not isinstance(value, (tuple, list)): + if not isinstance(value, tuple | list): errors.append( ConfigurableValueError( f"Incorrect value type - {type(value)}: should be list or tuple", diff --git a/model_api/python/model_api/models/yolo.py b/model_api/python/model_api/models/yolo.py index 37057905..c8e4fc43 100644 --- a/model_api/python/model_api/models/yolo.py +++ b/model_api/python/model_api/models/yolo.py @@ -318,7 +318,7 @@ def iou(box_1, box_2): def _parse_outputs(self, outputs, meta): detections = [] - for layer_name in self.yolo_layer_params.keys(): + for layer_name in self.yolo_layer_params: out_blob = outputs[layer_name] layer_params = self.yolo_layer_params[layer_name] out_blob.shape = layer_params[0] diff --git a/model_api/python/model_api/pipelines/async_pipeline.py b/model_api/python/model_api/pipelines/async_pipeline.py index 040a2684..3c72b6b9 100644 --- a/model_api/python/model_api/pipelines/async_pipeline.py +++ b/model_api/python/model_api/pipelines/async_pipeline.py @@ -5,7 +5,7 @@ from time import perf_counter -from ..performance_metrics import PerformanceMetrics +from model_api.performance_metrics import PerformanceMetrics class AsyncPipeline: diff --git a/model_api/python/pyproject.toml b/model_api/python/pyproject.toml index 349c43d2..1749647a 100644 --- a/model_api/python/pyproject.toml +++ b/model_api/python/pyproject.toml @@ -92,12 +92,12 @@ preview = true lint.select = [ # "F", # Pyflakes (`F`) "E", # pycodestyle error (`E`) - # "W", # pycodestyle warning (`W`) + "W", # pycodestyle warning (`W`) # "C90", # mccabe (`C90`) "I", # isort (`I`) # "N", # pep8-naming (`N`) # "D", # pydocstyle (`D`) - # "UP", # pyupgrade (`UP`) + "UP", # pyupgrade (`UP`) # "YTT", # flake8-2020 (`YTT`) # "ANN", # flake8-annotations (`ANN`) # "S", # flake8-bandit (`S`) @@ -106,9 +106,9 @@ lint.select = [ # "B", # flake8-bugbear (`B`) # "A", # flake8-builtins (`A`) # "COM", # flake8-commas (`COM`) - # "CPY", # flake8-copyright (`CPY`) + "CPY", # flake8-copyright (`CPY`) # "C4", # flake8-comprehensions (`C4`) - # "DTZ", # flake8-datatimez (`DTZ`) + "DTZ", # flake8-datatimez (`DTZ`) # "T10", # flake8-debugger (`T10`) # "EM", # flake8-errmsg (`EM`) # "FA", # flake8-future-annotations (`FA`) @@ -118,9 +118,9 @@ lint.select = [ # "PT", # flake8-pytest-style (`PT`) # "RSE", # flake8-raise (`RSE`) # "RET", # flake8-return (`RET`) - # "SLF", # flake8-self (`SLF`) - # "SIM", # flake8-simplify (`SIM`) - # "TID", # flake8-tidy-imports (`TID`) + "SLF", # flake8-self (`SLF`) + "SIM", # flake8-simplify (`SIM`) + "TID", # flake8-tidy-imports (`TID`) # "TCH", # flake8-type-checking (`TCH`) # "INT", # flake8-gettext (`INT`) # "ARG", # flake8-unsused-arguments (`ARG`) @@ -128,12 +128,12 @@ lint.select = [ # "TD", # flake8-todos (`TD`) # "FIX", # flake8-fixme (`FIX`) # "ERA", # eradicate (`ERA`) - # "PD", # pandas-vet (`PD`) - # "PGH", # pygrep-hooks (`PGH`) + "PD", # pandas-vet (`PD`) + "PGH", # pygrep-hooks (`PGH`) # "PL", # pylint (`PL`) # "TRY", # tryceratos (`TRY`) # "FLY", # flynt (`FLY`) - # "NPY", # NumPy-specific rules (`NPY`) + "NPY", # NumPy-specific rules (`NPY`) # "PERF", # Perflint (`PERF`) # "RUF", # Ruff-specific rules (`RUF`) # "FURB", # refurb (`FURB`) - ERROR: Unknown rule selector: `FURB` From 61e49d9356437dc034d729ef638b99cd28e497bd Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Thu, 31 Oct 2024 16:50:13 +0100 Subject: [PATCH 3/4] disable pyupgrade Signed-off-by: Ashwin Vaidya --- model_api/python/model_api/adapters/openvino_adapter.py | 2 +- model_api/python/pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/model_api/python/model_api/adapters/openvino_adapter.py b/model_api/python/model_api/adapters/openvino_adapter.py index 3fcb93c8..52dd74f1 100644 --- a/model_api/python/model_api/adapters/openvino_adapter.py +++ b/model_api/python/model_api/adapters/openvino_adapter.py @@ -133,7 +133,7 @@ def __init__( self.is_onnx_file = False self.onnx_metadata = {} - if isinstance(self.model_path, str | Path): + if isinstance(self.model_path, (str, Path)): if Path(self.model_path).suffix == ".onnx" and weights_path: log.warning( 'For model in ONNX format should set only "model_path" parameter.' diff --git a/model_api/python/pyproject.toml b/model_api/python/pyproject.toml index 1749647a..a8cd3eb3 100644 --- a/model_api/python/pyproject.toml +++ b/model_api/python/pyproject.toml @@ -97,7 +97,7 @@ lint.select = [ "I", # isort (`I`) # "N", # pep8-naming (`N`) # "D", # pydocstyle (`D`) - "UP", # pyupgrade (`UP`) + # "UP", # pyupgrade (`UP`) # need min python version 3.10 # "YTT", # flake8-2020 (`YTT`) # "ANN", # flake8-annotations (`ANN`) # "S", # flake8-bandit (`S`) From a68397dd711eedc36c6f8f1c4e431234076c6e40 Mon Sep 17 00:00:00 2001 From: Ashwin Vaidya Date: Thu, 31 Oct 2024 17:00:16 +0100 Subject: [PATCH 4/4] Fix incorrect type check in ListValue validation Signed-off-by: Ashwin Vaidya --- model_api/python/model_api/models/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model_api/python/model_api/models/types.py b/model_api/python/model_api/models/types.py index 0784baac..0ba3f0b7 100644 --- a/model_api/python/model_api/models/types.py +++ b/model_api/python/model_api/models/types.py @@ -187,7 +187,7 @@ def validate(self, value): errors = super().validate(value) if not value: return errors - if not isinstance(value, tuple | list): + if not isinstance(value, (tuple, list)): errors.append( ConfigurableValueError( f"Incorrect value type - {type(value)}: should be list or tuple",