@@ -126,9 +126,7 @@ class TextParsingDataItemEntity(BaseModel):
126126 def _check (cls , values : t .Dict [str , t .Any ]) -> t .Dict [str , t .Any ]:
127127 start = values .get ("start" )
128128 end = values .get ("end" )
129- assert start <= end or fail (
130- f"start={ start } is expected to be smaller than end={ end } "
131- )
129+ assert start <= end or fail (f"{ start = } is expected to be smaller than { end = } " )
132130 return values
133131
134132
@@ -161,6 +159,9 @@ class TextParsingDataItem(BaseModel):
161159 @model_validator (mode = "before" )
162160 @classmethod
163161 def _check (cls , values : t .Dict [str , t .Any ]) -> t .Dict [str , t .Any ]:
162+ if isinstance (values , list ):
163+ return [cls ._check (item ) for item in values ]
164+
164165 text = values .get ("text" )
165166 entities = values .get ("entities" )
166167 parsing = values .get ("parsing" )
@@ -179,15 +180,13 @@ def _check(cls, values: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
179180 parsed = text [entity ["start" ] : entity ["end" ]]
180181 holder = parsing [parsing_key_name ]
181182
182- assert parsed in holder or fail (
183- f"parsed='{ parsed } ' is expected to be in holder='{ holder } '"
184- )
183+ assert parsed in holder or fail (f"{ parsed = } is expected to be in { holder = } " )
185184
186185 return values
187186
188187
189188class TextParsingResponse (HrFlowAPIResponse ):
190- data : t .Optional [t .List [TextParsingDataItem ]] = None
189+ data : t .Optional [t .Union [ TextParsingDataItem , t . List [TextParsingDataItem ] ]] = None
191190
192191
193192class TextOCRDataItemPage (BaseModel ):
@@ -365,8 +364,7 @@ def _check(cls, values: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
365364 board_key = values .get ("board_key" )
366365 board = values .get ("board" )
367366 assert board_key == board ["key" ] or fail (
368- f"job.board_key='{ board_key } ' is expected to be the same as"
369- f" job.board.key='{ board ['key' ]} '"
367+ f"{ board_key = } is expected to be the same as { board ['key' ]= } "
370368 )
371369 return values
372370
@@ -461,8 +459,7 @@ def _check(cls, values: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
461459 source_key = values ["source_key" ]
462460 source = values ["source" ]
463461 assert source_key == source ["key" ] or fail (
464- f"profile.source_key='{ source_key } ' is expected to be the same as"
465- f" profile.source.key='{ source ['key' ]} '"
462+ f"{ source_key = } is expected to be the same as { source ['key' ]= } "
466463 )
467464 return values
468465
0 commit comments