@@ -142,6 +142,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
142142 return key
143143
144144
145+ def _no_transform_needed (annotation : type ) -> bool :
146+ return annotation == float or annotation == int
147+
148+
145149def _transform_recursive (
146150 data : object ,
147151 * ,
@@ -184,6 +188,15 @@ def _transform_recursive(
184188 return cast (object , data )
185189
186190 inner_type = extract_type_arg (stripped_type , 0 )
191+ if _no_transform_needed (inner_type ):
192+ # for some types there is no need to transform anything, so we can get a small
193+ # perf boost from skipping that work.
194+ #
195+ # but we still need to convert to a list to ensure the data is json-serializable
196+ if is_list (data ):
197+ return data
198+ return list (data )
199+
187200 return [_transform_recursive (d , annotation = annotation , inner_type = inner_type ) for d in data ]
188201
189202 if is_union_type (stripped_type ):
@@ -332,6 +345,15 @@ async def _async_transform_recursive(
332345 return cast (object , data )
333346
334347 inner_type = extract_type_arg (stripped_type , 0 )
348+ if _no_transform_needed (inner_type ):
349+ # for some types there is no need to transform anything, so we can get a small
350+ # perf boost from skipping that work.
351+ #
352+ # but we still need to convert to a list to ensure the data is json-serializable
353+ if is_list (data ):
354+ return data
355+ return list (data )
356+
335357 return [await _async_transform_recursive (d , annotation = annotation , inner_type = inner_type ) for d in data ]
336358
337359 if is_union_type (stripped_type ):
0 commit comments