Skip to content

docstrings

Functions:

validate_docstring

validate_docstring(raw: str) -> dict[str, Any]
Source code in src/arx/docstrings.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def validate_docstring(raw: str) -> dict[str, Any]:
    """
    title: Validate docstring content as Douki YAML.
    parameters:
      raw:
        type: str
        description: Raw text found inside the docstring block.
    returns:
      type: dict[str, Any]
    """
    normalized = textwrap.dedent(raw).strip()
    if not normalized:
        raise ValueError("Docstring block cannot be empty.")

    try:
        data = yaml.safe_load(normalized)
    except yaml.YAMLError as err:
        raise ValueError("Docstring content must be valid YAML.") from err

    if not isinstance(data, dict):
        raise ValueError("Docstring YAML must define an object mapping.")

    try:
        validate(instance=data, schema=_schema())
    except ValidationError as err:
        raise ValueError(
            f"Docstring YAML does not follow douki schema: {err.message}"
        ) from err

    return cast(dict[str, Any], data)