Skip to content

Commit 45727d4

Browse files
committed
removed duplicated get_auto_default_for_type, kept in engine_value and imported same in engine_object
1 parent 68a6e46 commit 45727d4

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

python/cocoindex/engine_object.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
AnalyzedDictType,
1818
AnalyzedListType,
1919
AnalyzedStructType,
20-
AnalyzedTypeInfo,
2120
AnalyzedUnionType,
2221
EnrichedValueType,
2322
FieldSchema,
@@ -27,6 +26,7 @@
2726
is_pydantic_model,
2827
extract_ndarray_elem_dtype,
2928
)
29+
from .engine_value import get_auto_default_for_type
3030

3131

3232
T = TypeVar("T")
@@ -37,30 +37,6 @@
3737
pass
3838

3939

40-
def _get_auto_default_for_type(
41-
type_info: AnalyzedTypeInfo,
42-
) -> tuple[Any, bool]:
43-
"""
44-
Get an auto-default value for a type annotation if it's safe to do so.
45-
46-
Returns:
47-
A tuple of (default_value, is_supported) where:
48-
- default_value: The default value if auto-defaulting is supported
49-
- is_supported: True if auto-defaulting is supported for this type
50-
"""
51-
# Case 1: Nullable types (Optional[T] or T | None)
52-
if type_info.nullable:
53-
return None, True
54-
55-
# Case 2: Table types (KTable or LTable) - check if it's a list or dict type
56-
if isinstance(type_info.variant, AnalyzedListType):
57-
return [], True
58-
elif isinstance(type_info.variant, AnalyzedDictType):
59-
return {}, True
60-
61-
return None, False
62-
63-
6440
def dump_engine_object(v: Any) -> Any:
6541
"""Recursively dump an object for engine. Engine side uses `Pythonized` to catch."""
6642
if v is None:
@@ -233,7 +209,7 @@ def load_engine_object(expected_type: Any, v: Any) -> Any:
233209

234210
for name, f_type in missing_fields:
235211
type_info = analyze_type_info(f_type)
236-
auto_default, is_supported = _get_auto_default_for_type(type_info)
212+
auto_default, is_supported = get_auto_default_for_type(type_info)
237213
if is_supported:
238214
init_kwargs[name] = auto_default
239215
return struct_type(**init_kwargs)

python/cocoindex/engine_value.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def decode_scalar(value: Any) -> Any | None:
439439
return lambda value: value
440440

441441

442-
def _get_auto_default_for_type(
442+
def get_auto_default_for_type(
443443
type_info: AnalyzedTypeInfo,
444444
) -> tuple[Any, bool]:
445445
"""
@@ -557,7 +557,7 @@ def make_closure_for_field(
557557
if default_value is not inspect.Parameter.empty:
558558
return lambda _: default_value
559559

560-
auto_default, is_supported = _get_auto_default_for_type(type_info)
560+
auto_default, is_supported = get_auto_default_for_type(type_info)
561561
if is_supported:
562562
warnings.warn(
563563
f"Field '{name}' (type {param.annotation}) without default value is missing in input: "

0 commit comments

Comments
 (0)