Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `ewokstasks` directive displays task tags.

### Changed

- `ewokstasks` directive: clear error for pydantic fields with non-list `examples`.

## [2.2.1] - 2026-04-21

### Fixed
Expand Down
11 changes: 9 additions & 2 deletions src/ewokssphinx/ewoks_task_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _parse_parameter_names(

def _parse_pydantic_model(model: Type[BaseModel]) -> list[ParameterDescription]:
return [
_parse_pydantic_field(name, field_info)
_parse_pydantic_field(model, name, field_info)
for name, field_info in model.model_fields.items()
]

Expand All @@ -141,8 +141,15 @@ def _parse_doc(text) -> str:
return inspect.cleandoc(text) if text else ""


def _parse_pydantic_field(name: str, field_info: FieldInfo) -> ParameterDescription:
def _parse_pydantic_field(
model: Type[BaseModel], name: str, field_info: FieldInfo
) -> ParameterDescription:
examples = getattr(field_info, "examples", None)
if examples is not None and not isinstance(examples, list):
raise TypeError(
f"'examples' of field '{name}' of '{qualname(model)}' must be a list, "
f"got {type(examples).__name__}"
)
default = getattr(field_info, "default", None)
if default is PydanticUndefined:
default = None
Expand Down
11 changes: 11 additions & 0 deletions src/ewokssphinx/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import pytest
from pydantic import BaseModel
from pydantic import Field

from ewokssphinx.ewoks_task_utils import _extract_submodels
from ewokssphinx.ewoks_task_utils import _parse_pydantic_model


class Type1(BaseModel):
Expand Down Expand Up @@ -44,3 +47,11 @@ def test_extract_type_inputs():
"ewokssphinx.tests.dummy_tasks_nested.Coordinates",
"ewokssphinx.tests.dummy_tasks_nested.Planet",
]


def test_parse_non_list_examples():
class Model(BaseModel):
resources: dict = Field(default={}, examples={"cpu": 0.5})

with pytest.raises(TypeError, match="resources"):
_parse_pydantic_model(Model)
Loading