def from_yaml()

in tools/yaml_parser.py [0:0]


  def from_yaml(
      cls: Type[EnumerableTagValuesValidatorType],
      yaml_config: Mapping[str, Any]) -> EnumerableTagValuesValidatorType:
    """Builds an EnumerableTagValuesValidator instance from a YAML config.

    Args:
      yaml_config: A config loaded from a YAML file.

    Returns:
      An EnumerableTagValuesValidator instance loaded from the YAML config.

    Raises:
      ValueError:
        - if yaml_config does not contain a `values` field.
        - if a tag item within yaml_config does not contain an `id` field.
    """

    if _VALUES_KEY not in yaml_config:
      raise ValueError(f"YAML config should contain `{_VALUES_KEY}` key "
                       f"but was {yaml_config}.")

    values = list()
    for item in yaml_config[_VALUES_KEY]:
      if _ID_KEY not in item:
        raise ValueError(f"A tag item must contain an `{_ID_KEY}` field "
                         f" but was {item}.")
      values.append(EnumerableTagValue(id=item[_ID_KEY]))
    return cls(values)