|
2 | 2 | import inspect # For function introspection |
3 | 3 | from enum import Enum |
4 | 4 | from typing import get_args, get_origin, Union, List, Any, Dict # For type hinting utilities |
| 5 | +from osbot_utils.type_safe.Type_Safe__Base import Type_Safe__Base |
5 | 6 | from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive |
6 | 7 | from osbot_utils.type_safe.type_safe_core.shared.Type_Safe__Annotations import type_safe_annotations |
7 | 8 | from osbot_utils.type_safe.type_safe_core.shared.Type_Safe__Shared__Variables import IMMUTABLE_TYPES |
@@ -244,18 +245,24 @@ def validate_direct_type(self, param_name: str, param_value: Any, expected_type: |
244 | 245 |
|
245 | 246 | if value_type is Any: # if value type is Any, we don't need to do any checks since they will all match |
246 | 247 | return True |
| 248 | + |
| 249 | + validator = Type_Safe__Base() |
247 | 250 | for k, v in param_value.items(): |
248 | | - if get_origin(key_type) is None: |
| 251 | + if get_origin(key_type) is None: # Validate key (existing logic) |
249 | 252 | if not isinstance(k, key_type): |
250 | 253 | raise ValueError(f"Dict key '{k}' expected type {key_type}, but got {type(k)}") |
251 | 254 | else: |
252 | | - raise NotImplementedError(f"Validation for subscripted key type '{key_type}' not yet supported in parameter '{param_name}'") |
| 255 | + try: |
| 256 | + validator.is_instance_of_type(k, key_type) |
| 257 | + except TypeError as e: |
| 258 | + raise ValueError(f"Dict key '{k}' in parameter '{param_name}': {e}") from None |
| 259 | + |
| 260 | + if value_type is not Any: # Validate value |
| 261 | + try: |
| 262 | + validator.is_instance_of_type(v, value_type) |
| 263 | + except TypeError as e: |
| 264 | + raise ValueError(f"Dict value for key '{k}' in parameter '{param_name}': {e}") from None |
253 | 265 |
|
254 | | - if get_origin(value_type) is None: |
255 | | - if not isinstance(v, value_type): |
256 | | - raise ValueError(f"Dict value for key '{k}' expected type {value_type}, but got {type(v)}") |
257 | | - elif value_type is not Any: |
258 | | - raise NotImplementedError(f"Validation for subscripted value type '{value_type}' not yet supported in parameter '{param_name}'") |
259 | 266 | return True |
260 | 267 | base_type = origin |
261 | 268 | else: |
|
0 commit comments