Skip to content

Commit 67e8c7a

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

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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
pass
3838

3939

40-
def _get_auto_default_for_type(
40+
def get_auto_default_for_type(
4141
type_info: AnalyzedTypeInfo,
4242
) -> tuple[Any, bool]:
4343
"""
@@ -233,7 +233,7 @@ def load_engine_object(expected_type: Any, v: Any) -> Any:
233233

234234
for name, f_type in missing_fields:
235235
type_info = analyze_type_info(f_type)
236-
auto_default, is_supported = _get_auto_default_for_type(type_info)
236+
auto_default, is_supported = get_auto_default_for_type(type_info)
237237
if is_supported:
238238
init_kwargs[name] = auto_default
239239
return struct_type(**init_kwargs)

python/cocoindex/engine_value.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import Any, Callable, Mapping, TypeVar
1111

1212
import numpy as np
13-
1413
from .typing import (
1514
AnalyzedAnyType,
1615
AnalyzedBasicType,
@@ -30,6 +29,7 @@
3029
StructType,
3130
TableType,
3231
)
32+
from .engine_object import get_auto_default_for_type
3333

3434

3535
T = TypeVar("T")
@@ -439,30 +439,6 @@ def decode_scalar(value: Any) -> Any | None:
439439
return lambda value: value
440440

441441

442-
def _get_auto_default_for_type(
443-
type_info: AnalyzedTypeInfo,
444-
) -> tuple[Any, bool]:
445-
"""
446-
Get an auto-default value for a type annotation if it's safe to do so.
447-
448-
Returns:
449-
A tuple of (default_value, is_supported) where:
450-
- default_value: The default value if auto-defaulting is supported
451-
- is_supported: True if auto-defaulting is supported for this type
452-
"""
453-
# Case 1: Nullable types (Optional[T] or T | None)
454-
if type_info.nullable:
455-
return None, True
456-
457-
# Case 2: Table types (KTable or LTable) - check if it's a list or dict type
458-
if isinstance(type_info.variant, AnalyzedListType):
459-
return [], True
460-
elif isinstance(type_info.variant, AnalyzedDictType):
461-
return {}, True
462-
463-
return None, False
464-
465-
466442
def make_engine_struct_decoder(
467443
field_path: list[str],
468444
src_fields: list[FieldSchema],
@@ -557,7 +533,7 @@ def make_closure_for_field(
557533
if default_value is not inspect.Parameter.empty:
558534
return lambda _: default_value
559535

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

0 commit comments

Comments
 (0)