def _get_property_list_from_dataclass()

in src/databao_context_engine/introspection/property_extract.py [0:0]


def _get_property_list_from_dataclass(parent_type: type) -> list[ConfigPropertyDefinition]:
    if not is_dataclass(parent_type):
        raise ValueError(f"{parent_type} is not a dataclass")

    dataclass_fields = fields(parent_type)

    result = []
    for field in dataclass_fields:
        has_field_default = field.default is not None and field.default != MISSING

        if isinstance(field.type, str):
            try:
                property_type = _evaluate_type_string(field.type)
            except Exception:
                continue
        else:
            property_type = field.type

        property_for_field = _create_property(
            property_type=property_type,
            property_name=field.name,
            property_default=field.default if has_field_default else None,
            is_property_required=not has_field_default,
        )

        if property_for_field is not None:
            result.append(property_for_field)

    return result