44
55import json
66
7+ from collections import deque
78from dataclasses import dataclass
89from typing import TYPE_CHECKING
910from typing import Any
1617
1718
1819if TYPE_CHECKING :
19- from collections import deque
20+ from collections . abc import Sequence
2021
2122
22- def to_path (schema_path : deque [Any ]) -> str :
23+ def to_path (schema_path : Sequence [Any ] | str ) -> str :
2324 """Flatten a path to a dot delimited string.
2425
2526 Args:
@@ -28,10 +29,11 @@ def to_path(schema_path: deque[Any]) -> str:
2829 Returns:
2930 The dot delimited path
3031 """
31- return "." .join (str (index ) for index in schema_path )
32+ queue = schema_path if isinstance (schema_path , deque ) else deque (schema_path )
33+ return "." .join (str (index ) for index in queue )
3234
3335
34- def json_path (absolute_path : deque [Any ]) -> str :
36+ def json_path (absolute_path : Sequence [Any ]) -> str :
3537 """Flatten a data path to a dot delimited string.
3638
3739 Args:
@@ -97,7 +99,7 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
9799
98100 if isinstance (schema , str ):
99101 schema = json .loads (schema )
100- if isinstance (schema , bool ):
102+ if isinstance (schema , ( bool , str ) ):
101103 msg = "Unexpected schema data."
102104 raise TypeError (msg )
103105 validator = validator_for (schema )
@@ -129,10 +131,10 @@ def validate(schema: str | dict[str, Any], data: dict[str, Any]) -> list[JsonSch
129131 data_path = to_path (validation_error .absolute_path ),
130132 json_path = json_path (validation_error .absolute_path ),
131133 schema_path = to_path (validation_error .relative_schema_path ),
132- relative_schema = validation_error .schema ,
133- expected = validation_error .validator_value ,
134- validator = validation_error .validator ,
135- found = validation_error .instance ,
134+ relative_schema = str ( validation_error .schema ) ,
135+ expected = str ( validation_error .validator_value ) ,
136+ validator = str ( validation_error .validator ) ,
137+ found = str ( validation_error .instance ) ,
136138 )
137139 errors .append (error )
138140 return errors
0 commit comments