Skip to content

Commit 18eea51

Browse files
committed
Enhance type hinting and improve code clarity across operators
- Added type hints for lists and dictionaries in various operator classes to improve code readability and maintainability. - Updated import statements to include type ignoring for YAML to prevent type checking issues. - Refined the initialization of file lists in the GenericDirectoryScanner operator for better type safety. Signed-off-by: Victor Chang <[email protected]>
1 parent e75bfa4 commit 18eea51

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

tools/pipeline-generator/pipeline_generator/config/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pathlib import Path
1515
from typing import Any, Dict, List, Optional, Union
1616

17-
import yaml
17+
import yaml # type: ignore
1818
from pydantic import BaseModel, Field
1919

2020

@@ -130,6 +130,7 @@ def load_config(config_path: Optional[Path] = None) -> Settings:
130130
model_id=None,
131131
base_url="https://huggingface.co",
132132
description="Official MONAI organization models",
133+
model_type=None,
133134
)
134135
]
135136
)

tools/pipeline-generator/pipeline_generator/templates/operators/generic_directory_scanner_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(
5656
self._case_sensitive = bool(case_sensitive)
5757

5858
# State tracking
59-
self._files = []
59+
self._files: list[Path] = []
6060
self._current_index = 0
6161

6262
super().__init__(fragment, *args, **kwargs)

tools/pipeline-generator/pipeline_generator/templates/operators/image_overlay_writer_operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def compute(self, op_input, op_output, context):
7474

7575
def _to_hwc_uint8(self, image) -> np.ndarray:
7676
if isinstance(image, Image):
77-
arr = image.asnumpy()
77+
arr: np.ndarray = image.asnumpy()
7878
else:
7979
arr = np.asarray(image)
8080
if arr.ndim != 3 or arr.shape[2] not in (3, 4):
@@ -89,7 +89,7 @@ def _to_hwc_uint8(self, image) -> np.ndarray:
8989

9090
def _to_mask_uint8(self, pred) -> np.ndarray:
9191
if isinstance(pred, Image):
92-
arr = pred.asnumpy()
92+
arr: np.ndarray = pred.asnumpy()
9393
else:
9494
arr = np.asarray(pred)
9595
arr = np.squeeze(arr)

tools/pipeline-generator/pipeline_generator/templates/operators/json_results_writer_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def compute(self, op_input, op_output, context):
9797

9898
def _process_prediction(self, pred: Any, filename: str) -> Dict[str, Any]:
9999
"""Process various prediction formats into a JSON-serializable dictionary."""
100-
result = {"filename": filename}
100+
result: Dict[str, Any] = {"filename": filename}
101101

102102
# Handle dictionary predictions (e.g., from MonaiBundleInferenceOperator)
103103
if isinstance(pred, dict):

tools/pipeline-generator/pipeline_generator/templates/operators/llama3_vila_inference_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _create_image_overlay(self, image: Image, text: str) -> Image:
224224
# Break text into lines for better display
225225
words = text.split()
226226
lines = []
227-
current_line = []
227+
current_line: list[str] = []
228228
max_width = pil_image.width - 20 # Leave margin
229229

230230
# Simple text wrapping (in production, use proper text metrics)

tools/pipeline-generator/pipeline_generator/templates/operators/prompts_loader_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Any, Dict, List, Optional
1616

1717
import numpy as np
18-
import yaml
18+
import yaml # type: ignore
1919

2020
from monai.deploy.core import Fragment, Image, Operator, OperatorSpec
2121
from monai.deploy.utils.importutil import optional_import

0 commit comments

Comments
 (0)