fix: resolve CI linting and type checking issues
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-02-04 22:07:47 +00:00
parent 448afffd17
commit 2d4e7b091b

View File

@@ -1,9 +1,9 @@
"""Schema inference and validation module.""" """Schema inference and validation module."""
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Tuple, Union from typing import Any, Dict, List, Optional, Tuple
from pydantic import BaseModel, ValidationError, field_validator from pydantic import BaseModel, field_validator
class SchemaType: class SchemaType:
@@ -57,6 +57,10 @@ class InferredSchema:
description: str = "" description: str = ""
items: Optional[SchemaProperty] = None items: Optional[SchemaProperty] = None
def __post_init__(self) -> None:
if self.properties is None:
self.properties = []
def to_dict(self) -> Dict[str, Any]: def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary.""" """Convert to dictionary."""
result: Dict[str, Any] = { result: Dict[str, Any] = {
@@ -199,7 +203,7 @@ class SchemaValidator:
def validate(self, data: Any) -> Tuple[bool, List[str]]: def validate(self, data: Any) -> Tuple[bool, List[str]]:
"""Validate data against schema.""" """Validate data against schema."""
errors = [] errors: List[str] = []
is_valid = self._validate_value(data, self.schema, "", errors) is_valid = self._validate_value(data, self.schema, "", errors)
return is_valid, errors return is_valid, errors
@@ -226,9 +230,8 @@ class SchemaValidator:
prop_path = f"{path}.{prop.name}" if path else prop.name prop_path = f"{path}.{prop.name}" if path else prop.name
if prop.name in value: if prop.name in value:
prop_value = value[prop.name] prop_value = value[prop.name]
prop_schema = InferredSchema( prop_props: List[SchemaProperty] = prop.properties if prop.properties else []
root_type=prop.type, properties=prop.properties prop_schema = InferredSchema(root_type=prop.type, properties=prop_props) # type: ignore[arg-type]
)
self._validate_value(prop_value, prop_schema, prop_path, errors) self._validate_value(prop_value, prop_schema, prop_path, errors)
elif prop.required: elif prop.required:
errors.append(f"{prop_path}: required property missing") errors.append(f"{prop_path}: required property missing")
@@ -238,10 +241,8 @@ class SchemaValidator:
errors.append(f"{path}: expected array, got {actual_type}") errors.append(f"{path}: expected array, got {actual_type}")
return False return False
if isinstance(value, list) and schema.items: if isinstance(value, list) and schema.items:
item_schema = InferredSchema( item_props: List[SchemaProperty] = schema.items.properties if schema.items.properties else []
root_type=schema.items.type, item_schema = InferredSchema(root_type=schema.items.type, properties=item_props) # type: ignore[arg-type]
properties=schema.items.properties if schema.items.properties else None,
)
for i, item in enumerate(value): for i, item in enumerate(value):
self._validate_value(item, item_schema, f"{path}[{i}]", errors) self._validate_value(item, item_schema, f"{path}[{i}]", errors)