|
10 | 10 | from typing import Any, Callable, Mapping, TypeVar |
11 | 11 |
|
12 | 12 | import numpy as np |
13 | | - |
14 | 13 | from .typing import ( |
15 | 14 | AnalyzedAnyType, |
16 | 15 | AnalyzedBasicType, |
|
30 | 29 | StructType, |
31 | 30 | TableType, |
32 | 31 | ) |
| 32 | +from .engine_object import get_auto_default_for_type |
33 | 33 |
|
34 | 34 |
|
35 | 35 | T = TypeVar("T") |
@@ -439,30 +439,6 @@ def decode_scalar(value: Any) -> Any | None: |
439 | 439 | return lambda value: value |
440 | 440 |
|
441 | 441 |
|
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 | | - |
466 | 442 | def make_engine_struct_decoder( |
467 | 443 | field_path: list[str], |
468 | 444 | src_fields: list[FieldSchema], |
@@ -557,7 +533,7 @@ def make_closure_for_field( |
557 | 533 | if default_value is not inspect.Parameter.empty: |
558 | 534 | return lambda _: default_value |
559 | 535 |
|
560 | | - auto_default, is_supported = _get_auto_default_for_type(type_info) |
| 536 | + auto_default, is_supported = get_auto_default_for_type(type_info) |
561 | 537 | if is_supported: |
562 | 538 | warnings.warn( |
563 | 539 | f"Field '{name}' (type {param.annotation}) without default value is missing in input: " |
|
0 commit comments