Skip to content

Commit ff4c090

Browse files
committed
refactor(convert): reorganize struct to dict binding logic for clarity and maintainability
1 parent dfd522e commit ff4c090

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

python/cocoindex/convert.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@ def make_engine_value_decoder(
8686
or dst_annotation is inspect.Parameter.empty
8787
or dst_annotation is Any
8888
)
89-
# Handle struct -> dict binding for explicit dict annotations
90-
is_dict_annotation = False
91-
if dst_annotation is dict:
92-
is_dict_annotation = True
93-
elif getattr(dst_annotation, "__origin__", None) is dict:
94-
args = getattr(dst_annotation, "__args__", ())
95-
if args == (str, Any):
96-
is_dict_annotation = True
9789
if dst_is_any:
9890
if src_type_kind == "Union":
9991
return lambda value: value[1]
@@ -105,6 +97,15 @@ def make_engine_value_decoder(
10597
f"It's required for {src_type_kind} type."
10698
)
10799
return lambda value: value
100+
101+
# Handle struct -> dict binding for explicit dict annotations
102+
is_dict_annotation = False
103+
if dst_annotation is dict:
104+
is_dict_annotation = True
105+
elif getattr(dst_annotation, "__origin__", None) is dict:
106+
args = getattr(dst_annotation, "__args__", ())
107+
if args == (str, Any):
108+
is_dict_annotation = True
108109
if is_dict_annotation and src_type_kind == "Struct":
109110
return _make_engine_struct_to_dict_decoder(field_path, src_type["fields"])
110111

0 commit comments

Comments
 (0)