Exemple #1
0
def expand_map(original_root: object, the_dict: Dict[object, object],
               stack: List[str]) -> Map:

    if len(the_dict) != 1:
        raise DagsterInvalidConfigDefinitionError(
            original_root, the_dict, stack, "Map dict must be of length 1")

    key = list(the_dict.keys())[0]
    key_type = _convert_potential_type(original_root, key, stack)
    if not key_type or not key_type.kind == ConfigTypeKind.SCALAR:
        raise DagsterInvalidConfigDefinitionError(
            original_root,
            the_dict,
            stack,
            "Map dict must have a scalar type as its only key. Got key {}".
            format(repr(key)),
        )

    inner_type = _convert_potential_type(original_root, the_dict[key], stack)
    if not inner_type:
        raise DagsterInvalidConfigDefinitionError(
            original_root,
            the_dict,
            stack,
            "Map must have a single value and contain a valid type i.e. {{str: int}}. Got item {}"
            .format(repr(the_dict[key])),
        )

    return Map(key_type, inner_type)
def _convert_potential_field(original_root, potential_field, stack):
    from .field import Field

    if potential_field is None:
        raise DagsterInvalidConfigDefinitionError(
            original_root, potential_field, stack, reason="Fields cannot be None"
        )

    if not is_potential_field(potential_field):
        raise DagsterInvalidConfigDefinitionError(original_root, potential_field, stack)

    if isinstance(potential_field, Field):
        return potential_field

    return Field(_convert_potential_type(original_root, potential_field, stack))
Exemple #3
0
def expand_list(original_root: object, the_list: List[object],
                stack: List[str]) -> Array:

    if len(the_list) != 1:
        raise DagsterInvalidConfigDefinitionError(original_root, the_list,
                                                  stack,
                                                  "List must be of length 1")

    inner_type = _convert_potential_type(original_root, the_list[0], stack)
    if not inner_type:
        raise DagsterInvalidConfigDefinitionError(
            original_root,
            the_list,
            stack,
            "List have a single item and contain a valid type i.e. [int]. Got item {}"
            .format(repr(the_list[0])),
        )

    return Array(inner_type)
def expand_list(original_root, the_list, stack):
    from .config_type import Array

    if len(the_list) != 1:
        raise DagsterInvalidConfigDefinitionError(original_root, the_list,
                                                  stack,
                                                  'List must be of length 1')

    inner_type = _convert_potential_type(original_root, the_list[0], stack)
    if not inner_type:
        raise DagsterInvalidConfigDefinitionError(
            original_root,
            the_list,
            stack,
            'List have a single item and contain a valid type i.e. [int]. Got item {}'
            .format(repr(the_list[0])),
        )

    return Array(inner_type)