Skip to content

Commit ab2cec9

Browse files
committed
support pydantic models in write_yaml
1 parent d4a0289 commit ab2cec9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

bioimageio/spec/_internal/io_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import numpy
2121
from loguru import logger
2222
from numpy.typing import NDArray
23-
from pydantic import FilePath, NewPath, RootModel
23+
from pydantic import BaseModel, FilePath, NewPath, RootModel
2424
from ruyaml import YAML
2525
from typing_extensions import Unpack
2626

@@ -70,7 +70,7 @@ def read_yaml(
7070

7171

7272
def write_yaml(
73-
content: Union[YamlValue, BioimageioYamlContentView],
73+
content: Union[YamlValue, BioimageioYamlContentView, BaseModel],
7474
/,
7575
file: Union[NewPath, FilePath, IO[str], IO[bytes], ZipPath],
7676
):
@@ -79,6 +79,9 @@ def write_yaml(
7979
else:
8080
cm = nullcontext(file)
8181

82+
if isinstance(content, BaseModel):
83+
content = content.model_dump(mode="json")
84+
8285
with cm as f:
8386
_yaml_dump.dump(content, f)
8487

0 commit comments

Comments
 (0)