Skip to content

Commit 727d123

Browse files
committed
[feat] Add validation for func output
1 parent 5bc133a commit 727d123

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/oqd_dataschema/datastore.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import json
2020
import pathlib
21-
from typing import Any, Dict, Literal
21+
from typing import Any, Callable, Dict, Literal
2222

2323
import h5py
2424
from pydantic import (
@@ -220,8 +220,16 @@ def add(self, **groups):
220220

221221
self.update(**groups)
222222

223-
def pipe(self, func) -> Datastore:
224-
return func(self)
223+
def pipe(self, func: Callable[[Datastore], Datastore]) -> Datastore:
224+
_result = func(self)
225+
226+
if _result is None:
227+
return self
228+
229+
if _result is not Datastore:
230+
raise ValueError("`func` must return None or Datastore.")
231+
232+
return _result
225233

226234

227235
# %%

0 commit comments

Comments
 (0)