|
6 | 6 | import re
|
7 | 7 | import shlex
|
8 | 8 | from pathlib import Path
|
9 |
| -from typing import Annotated, Any, Literal |
| 9 | +from typing import Annotated, Any, Literal, cast |
10 | 10 |
|
11 | 11 | # third party imports
|
12 | 12 | try:
|
@@ -141,11 +141,7 @@ def validate_inputs(self, provided_inputs: dict[str, str]) -> list[str]:
|
141 | 141 | return []
|
142 | 142 |
|
143 | 143 | required_input_ids = self.get_required_inputs()
|
144 |
| - missing_inputs = [] |
145 |
| - |
146 |
| - for input_id in required_input_ids: |
147 |
| - if input_id not in provided_inputs: |
148 |
| - missing_inputs.append(input_id) |
| 144 | + missing_inputs = [input_id for input_id in required_input_ids if input_id not in provided_inputs] |
149 | 145 |
|
150 | 146 | return missing_inputs
|
151 | 147 |
|
@@ -175,24 +171,23 @@ def replace_input(match: re.Match[str]) -> str:
|
175 | 171 | return re.sub(r"\$\{input:([^}]+)\}", replace_input, data)
|
176 | 172 |
|
177 | 173 | elif isinstance(data, dict):
|
178 |
| - result = {} # type: ignore |
179 |
| - for k, v in data.items(): # type: ignore |
180 |
| - result[k] = cls._substitute_inputs(v, inputs) # type: ignore |
181 |
| - return result |
| 174 | + dict_result: dict[str, Any] = {} |
| 175 | + dict_data = cast(dict[str, Any], data) |
| 176 | + for k, v in dict_data.items(): |
| 177 | + dict_result[k] = cls._substitute_inputs(v, inputs) |
| 178 | + return dict_result |
182 | 179 |
|
183 | 180 | elif isinstance(data, list):
|
184 |
| - result = [] # type: ignore |
185 |
| - for item in data: # type: ignore |
186 |
| - result.append(cls._substitute_inputs(item, inputs)) # type: ignore |
187 |
| - return result |
| 181 | + list_data = cast(list[Any], data) |
| 182 | + return [cls._substitute_inputs(item, inputs) for item in list_data] |
188 | 183 |
|
189 | 184 | else:
|
190 | 185 | return data
|
191 | 186 |
|
192 | 187 | @classmethod
|
193 | 188 | def _strip_json_comments(cls, content: str) -> str:
|
194 | 189 | """Strip // comments from JSON content, being careful not to remove // inside strings."""
|
195 |
| - result = [] |
| 190 | + result: list[str] = [] |
196 | 191 | lines = content.split("\n")
|
197 | 192 |
|
198 | 193 | for line in lines:
|
@@ -266,12 +261,12 @@ def from_file(
|
266 | 261 | if inputs is not None and preliminary_config.inputs:
|
267 | 262 | missing_inputs = preliminary_config.validate_inputs(inputs)
|
268 | 263 | if missing_inputs:
|
269 |
| - descriptions = [] |
| 264 | + descriptions: list[str] = [] |
270 | 265 | for input_id in missing_inputs:
|
271 | 266 | desc = preliminary_config.get_input_description(input_id)
|
272 | 267 | descriptions.append(f" - {input_id}: {desc or 'No description'}")
|
273 | 268 |
|
274 |
| - raise ValueError(f"Missing required input values:\n" + "\n".join(descriptions)) |
| 269 | + raise ValueError("Missing required input values:\n" + "\n".join(descriptions)) |
275 | 270 |
|
276 | 271 | # Substitute input placeholders if inputs provided
|
277 | 272 | if inputs:
|
|
0 commit comments