File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1232,20 +1232,26 @@ def _submit_request_and_process(
12321232 )
12331233
12341234 def _convert_to_model (
1235- self , data : list [dict [str , Any ]]
1235+ self ,
1236+ data : list [dict [str , Any ]] | Iterator ,
12361237 ) -> list [BaseModel ] | list [dict [str , Any ]]:
12371238 """Converts dictionary documents to instantiated MPDataDoc objects.
12381239
12391240 Args:
1240- data (list[dict]): Raw dictionary data objects
1241+ data (list[dict] or Iterator ): Raw dictionary data objects
12411242
12421243 Returns:
12431244 (list[MPDataDoc]): List of MPDataDoc objects
12441245
12451246 """
1246- if (hasattr (data , "__len__" ) and len (data ) > 0 ) or (hasattr (data , "__next__" )):
1247+ if (hasattr (data , "__len__" ) and len (data ) > 0 ) or (hasattr (data , "__next__" )): # type: ignore[arg-type]
12471248 is_list = hasattr (data , "__len__" )
1248- first_doc = data [0 ] if is_list else next (data )
1249+ try :
1250+ # Handle both list-like and iterator input
1251+ first_doc = data [0 ] if is_list else next (data ) # type: ignore[index,arg-type]
1252+ except StopIteration :
1253+ # Return empty list if no data in iterator
1254+ return []
12491255 data_model , set_fields , _ = self ._generate_returned_model (first_doc )
12501256
12511257 return [
You can’t perform that action at this time.
0 commit comments