fix: resolve CI/CD test and lint failures
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-02-03 05:31:46 +00:00
parent e75d4de3d5
commit 4e060d19d2

View File

@@ -37,19 +37,17 @@ def parse_type_spec(type_spec: TypeSpec) -> Tuple[str, Optional[Dict[str, Any]]]
return "unknown", None return "unknown", None
def check_type( def check_type(value: Any, expected_type: TypeSpec) -> Tuple[bool, Optional[str]]:
value: Any, expected_type: TypeSpec
) -> Tuple[bool, Optional[str]]:
"""Check if a value matches the expected type specification.""" """Check if a value matches the expected type specification."""
actual_type = infer_type(value) actual_type = infer_type(value)
type_name, type_info = parse_type_spec(expected_type) type_name, type_info = parse_type_spec(expected_type)
if type_name == "any": if type_name == "any":
return True, None return True, None
if actual_type != type_name: if actual_type != type_name:
return False, f"Expected {type_name}, got {actual_type}" return False, f"Expected {type_name}, got {actual_type}"
if type_name == "object" and isinstance(type_info, dict): if type_name == "object" and isinstance(type_info, dict):
properties = type_info.get("properties", {}) properties = type_info.get("properties", {})
required = type_info.get("required", []) required = type_info.get("required", [])
@@ -58,12 +56,12 @@ def check_type(
prop_valid, error = check_type(value[prop_name], prop_type) prop_valid, error = check_type(value[prop_name], prop_type)
if not prop_valid: if not prop_valid:
return False, f"Property '{prop_name}': {error}" return False, f"Property '{prop_name}': {error}"
if isinstance(required, list): if isinstance(required, list):
for req_prop in required: for req_prop in required:
if req_prop not in value: if req_prop not in value:
return False, f"Missing required property: '{req_prop}'" return False, f"Missing required property: '{req_prop}'"
if type_name == "array" and isinstance(type_info, dict): if type_name == "array" and isinstance(type_info, dict):
items = type_info.get("items") items = type_info.get("items")
if items is not None: if items is not None:
@@ -71,13 +69,11 @@ def check_type(
item_valid, error = check_type(item, items) item_valid, error = check_type(item, items)
if not item_valid: if not item_valid:
return False, f"Array item {i}: {error}" return False, f"Array item {i}: {error}"
return True, None return True, None
def validate_types( def validate_types(data: Any, type_spec: TypeSpec, path: str = "root") -> List[str]:
data: Any, type_spec: TypeSpec, path: str = "root"
) -> List[str]:
"""Validate data against a type specification and return all errors.""" """Validate data against a type specification and return all errors."""
errors = [] errors = []
valid, error = check_type(data, type_spec) valid, error = check_type(data, type_spec)
@@ -106,11 +102,11 @@ def validate_types(
def infer_schema_from_data(data: Any) -> Dict[str, Any]: def infer_schema_from_data(data: Any) -> Dict[str, Any]:
"""Infer a JSON Schema from data.""" """Infer a JSON Schema from data."""
schema: Dict[str, Any] = {} schema: Dict[str, Any] = {}
def build_schema(value: Any, schema_obj: Dict[str, Any]) -> None: def build_schema(value: Any, schema_obj: Dict[str, Any]) -> None:
type_name = infer_type(value) type_name = infer_type(value)
schema_obj["type"] = type_name schema_obj["type"] = type_name
if type_name == "object" and isinstance(value, dict): if type_name == "object" and isinstance(value, dict):
schema_obj["properties"] = {} schema_obj["properties"] = {}
required = [] required = []
@@ -122,10 +118,10 @@ def infer_schema_from_data(data: Any) -> Dict[str, Any]:
required.append(key) required.append(key)
if required: if required:
schema_obj["required"] = required schema_obj["required"] = required
elif type_name == "array" and isinstance(value, list) and value: elif type_name == "array" and isinstance(value, list) and value:
schema_obj["items"] = {} schema_obj["items"] = {}
build_schema(value[0], schema_obj["items"]) build_schema(value[0], schema_obj["items"])
build_schema(data, schema) build_schema(data, schema)
return schema return schema