def _unwrap_field_type()

in common/py_libs/config_spec.py [0:0]


def _unwrap_field_type(field_type: Type[object]) -> List[Type[object]]:
    """Returns a list of potential field types wrapped by List and Union. """
    logging.debug("Unwrapping field_type: %s", field_type)
    is_list = typing.get_origin(field_type) == list
    is_union = typing.get_origin(field_type) == Union  # pylint: disable=comparison-with-callable

    # For lists, recursively unwrap the element type.
    if is_list:
        if not typing.get_args(field_type):
            raise cortex_exc.TypeCError(
                "Lists must define an element datatype.")

        field_type = typing.get_args(field_type)[0]
        return _unwrap_field_type(field_type)

    # For unions, recursively unwrap all potential types.
    all_field_types = []
    if is_union:
        field_types = typing.get_args(field_type)
        for ft in field_types:
            all_field_types.extend(_unwrap_field_type(ft))
    # For single types, still return in a list.
    else:
        all_field_types.append(field_type)

    logging.debug("potential field_types: %s", all_field_types)
    return all_field_types