@@ -210,32 +210,39 @@ def streamable_from_dict(klass: type[_T_Streamable], item: Any) -> _T_Streamable
210
210
211
211
212
212
def function_to_convert_one_item (
213
- f_type : type [Any ], json_parser : Optional [Callable [[object ], Streamable ]] = None
213
+ f_type : type [Any ], json_parsers : Optional [list [ Callable [[object ], Streamable ] ]] = None
214
214
) -> ConvertFunctionType :
215
215
if is_type_SpecificOptional (f_type ):
216
- convert_inner_func = function_to_convert_one_item (get_args (f_type )[0 ], json_parser )
216
+ convert_inner_func = function_to_convert_one_item (get_args (f_type )[0 ], json_parsers )
217
217
return lambda item : convert_optional (convert_inner_func , item )
218
218
elif is_type_Tuple (f_type ):
219
219
args = get_args (f_type )
220
220
convert_inner_tuple_funcs = []
221
221
for arg in args :
222
- convert_inner_tuple_funcs .append (function_to_convert_one_item (arg , json_parser ))
222
+ convert_inner_tuple_funcs .append (function_to_convert_one_item (arg , json_parsers ))
223
223
# Ignoring for now as the proper solution isn't obvious
224
224
return lambda items : convert_tuple (convert_inner_tuple_funcs , items ) # type: ignore[arg-type]
225
225
elif is_type_List (f_type ):
226
226
inner_type = get_args (f_type )[0 ]
227
- convert_inner_func = function_to_convert_one_item (inner_type , json_parser )
227
+ convert_inner_func = function_to_convert_one_item (inner_type , json_parsers )
228
228
# Ignoring for now as the proper solution isn't obvious
229
229
return lambda items : convert_list (convert_inner_func , items ) # type: ignore[arg-type]
230
230
elif is_type_Dict (f_type ):
231
231
inner_types = get_args (f_type )
232
- key_converter = function_to_convert_one_item (inner_types [0 ], json_parser )
233
- value_converter = function_to_convert_one_item (inner_types [1 ], json_parser )
232
+ if json_parsers is None :
233
+ key_parsers = None
234
+ value_parsers = None
235
+ else :
236
+ key_parsers = [json_parsers [0 ]]
237
+ value_parsers = [json_parsers [1 ]]
238
+ key_converter = function_to_convert_one_item (inner_types [0 ], key_parsers )
239
+ value_converter = function_to_convert_one_item (inner_types [1 ], value_parsers )
234
240
return lambda mapping : convert_dict (key_converter , value_converter , mapping ) # type: ignore[arg-type]
235
241
elif hasattr (f_type , "from_json_dict" ):
236
- if json_parser is None :
237
- json_parser = f_type .from_json_dict
238
- return json_parser
242
+ if json_parsers is None :
243
+ return f_type .from_json_dict # type: ignore[no-any-return]
244
+ else :
245
+ return json_parsers [0 ]
239
246
elif issubclass (f_type , bytes ):
240
247
# Type is bytes, data is a hex string or bytes
241
248
return lambda item : convert_byte_type (f_type , item )
0 commit comments