Skip to content

Commit 6f12d2c

Browse files
agnersclaude
andauthored
Fix type annotations in addon options validation (#6392)
* Fix type annotations in addon options validation The type annotations for validation methods in AddonOptions and UiOptions were overly restrictive and did not match runtime behavior: - _nested_validate_list and _nested_validate_dict receive user input that could be any type, with runtime isinstance checks to validate. Changed parameter types from list[Any]/dict[Any, Any] to Any. - _ui_schema_element handles str, list, and dict values depending on the schema structure. Changed from str to the union type. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Fix type annotations in addon options validation Add missing type annotations to AddonOptions and UiOptions classes: - Add parameter and return type to AddonOptions.__call__ - Add explicit type annotation to UiOptions.coresys attribute - Add return type to UiOptions._ui_schema_element method 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent f0db82d commit 6f12d2c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

supervisor/addons/options.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def validate(self) -> vol.Schema:
7575
"""Create a schema for add-on options."""
7676
return vol.Schema(vol.All(dict, self))
7777

78-
def __call__(self, struct):
78+
def __call__(self, struct: dict[str, Any]) -> dict[str, Any]:
7979
"""Create schema validator for add-ons options."""
8080
options = {}
8181

@@ -193,9 +193,7 @@ def _single_validate(self, typ: str, value: Any, key: str) -> Any:
193193
f"Fatal error for option '{key}' with type '{typ}' in {self._name} ({self._slug})"
194194
) from None
195195

196-
def _nested_validate_list(
197-
self, typ: Any, data_list: list[Any], key: str
198-
) -> list[Any]:
196+
def _nested_validate_list(self, typ: Any, data_list: Any, key: str) -> list[Any]:
199197
"""Validate nested items."""
200198
options = []
201199

@@ -213,7 +211,7 @@ def _nested_validate_list(
213211
return options
214212

215213
def _nested_validate_dict(
216-
self, typ: dict[Any, Any], data_dict: dict[Any, Any], key: str
214+
self, typ: dict[Any, Any], data_dict: Any, key: str
217215
) -> dict[Any, Any]:
218216
"""Validate nested items."""
219217
options = {}
@@ -264,7 +262,7 @@ class UiOptions(CoreSysAttributes):
264262

265263
def __init__(self, coresys: CoreSys) -> None:
266264
"""Initialize UI option render."""
267-
self.coresys = coresys
265+
self.coresys: CoreSys = coresys
268266

269267
def __call__(self, raw_schema: dict[str, Any]) -> list[dict[str, Any]]:
270268
"""Generate UI schema."""
@@ -279,10 +277,10 @@ def __call__(self, raw_schema: dict[str, Any]) -> list[dict[str, Any]]:
279277
def _ui_schema_element(
280278
self,
281279
ui_schema: list[dict[str, Any]],
282-
value: str,
280+
value: str | list[Any] | dict[str, Any],
283281
key: str,
284282
multiple: bool = False,
285-
):
283+
) -> None:
286284
if isinstance(value, list):
287285
# nested value list
288286
assert not multiple

0 commit comments

Comments
 (0)