Skip to content

YAML Loader

YamlLoader

Bases: BaseLoader

Loads a YadsSpec from a YAML string.

Source code in src/yads/loaders/yaml_loader.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class YamlLoader(BaseLoader):
    """Loads a `YadsSpec` from a YAML string."""

    def load(self, content: str) -> YadsSpec:
        """Parses the YAML content and builds the spec.

        Args:
            content: The YAML string content.

        Returns:
            A `YadsSpec` instance.

        Raises:
            SpecParsingError: If the YAML content is invalid or does not
                              parse to a dictionary.
        """
        raw_data = yaml.safe_load(content)
        if not isinstance(raw_data, dict):
            raise SpecParsingError("Loaded YAML content did not parse to a dictionary.")
        data = cast(dict[str, Any], raw_data)
        return DictLoader().load(data)

load(content)

Parses the YAML content and builds the spec.

Parameters:

Name Type Description Default
content str

The YAML string content.

required

Returns:

Type Description
YadsSpec

A YadsSpec instance.

Raises:

Type Description
SpecParsingError

If the YAML content is invalid or does not parse to a dictionary.

Source code in src/yads/loaders/yaml_loader.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def load(self, content: str) -> YadsSpec:
    """Parses the YAML content and builds the spec.

    Args:
        content: The YAML string content.

    Returns:
        A `YadsSpec` instance.

    Raises:
        SpecParsingError: If the YAML content is invalid or does not
                          parse to a dictionary.
    """
    raw_data = yaml.safe_load(content)
    if not isinstance(raw_data, dict):
        raise SpecParsingError("Loaded YAML content did not parse to a dictionary.")
    data = cast(dict[str, Any], raw_data)
    return DictLoader().load(data)