@@ -142,6 +142,10 @@ def _maybe_transform_key(key: str, type_: type) -> str:
142
142
return key
143
143
144
144
145
+ def _no_transform_needed (annotation : type ) -> bool :
146
+ return annotation == float or annotation == int
147
+
148
+
145
149
def _transform_recursive (
146
150
data : object ,
147
151
* ,
@@ -184,6 +188,15 @@ def _transform_recursive(
184
188
return cast (object , data )
185
189
186
190
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
+
187
200
return [_transform_recursive (d , annotation = annotation , inner_type = inner_type ) for d in data ]
188
201
189
202
if is_union_type (stripped_type ):
@@ -332,6 +345,15 @@ async def _async_transform_recursive(
332
345
return cast (object , data )
333
346
334
347
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
+
335
357
return [await _async_transform_recursive (d , annotation = annotation , inner_type = inner_type ) for d in data ]
336
358
337
359
if is_union_type (stripped_type ):
0 commit comments