|
17 | 17 | AnalyzedDictType, |
18 | 18 | AnalyzedListType, |
19 | 19 | AnalyzedStructType, |
20 | | - AnalyzedTypeInfo, |
21 | 20 | AnalyzedUnionType, |
22 | 21 | EnrichedValueType, |
23 | 22 | FieldSchema, |
|
27 | 26 | is_pydantic_model, |
28 | 27 | extract_ndarray_elem_dtype, |
29 | 28 | ) |
| 29 | +from .engine_value import get_auto_default_for_type |
30 | 30 |
|
31 | 31 |
|
32 | 32 | T = TypeVar("T") |
|
37 | 37 | pass |
38 | 38 |
|
39 | 39 |
|
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 | | - |
64 | 40 | def dump_engine_object(v: Any) -> Any: |
65 | 41 | """Recursively dump an object for engine. Engine side uses `Pythonized` to catch.""" |
66 | 42 | if v is None: |
@@ -233,7 +209,7 @@ def load_engine_object(expected_type: Any, v: Any) -> Any: |
233 | 209 |
|
234 | 210 | for name, f_type in missing_fields: |
235 | 211 | 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) |
237 | 213 | if is_supported: |
238 | 214 | init_kwargs[name] = auto_default |
239 | 215 | return struct_type(**init_kwargs) |
|
0 commit comments