From 62bb8636a3d7156bc0caab5f574b1fa72445cead Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 02:46:25 +0000 Subject: [PATCH] fix: don't use dicts as iterables in transform (#724) --- src/anthropic/_utils/_transform.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/anthropic/_utils/_transform.py b/src/anthropic/_utils/_transform.py index 47e262a5..7e9663d3 100644 --- a/src/anthropic/_utils/_transform.py +++ b/src/anthropic/_utils/_transform.py @@ -173,6 +173,11 @@ def _transform_recursive( # Iterable[T] or (is_iterable_type(stripped_type) and is_iterable(data) and not isinstance(data, str)) ): + # dicts are technically iterable, but it is an iterable on the keys of the dict and is not usually + # intended as an iterable, so we don't transform it. + if isinstance(data, dict): + return cast(object, data) + inner_type = extract_type_arg(stripped_type, 0) return [_transform_recursive(d, annotation=annotation, inner_type=inner_type) for d in data]