Skip to content

Commit

Permalink
Revert "replace KwargsNode with TypedDict"
Browse files Browse the repository at this point in the history
This reverts commit 6e2ed71.
  • Loading branch information
FynnBe committed Nov 28, 2023
1 parent 1f8ad84 commit c6cd1c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions bioimageio/spec/_internal/base_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ def _serialize(self) -> str:
return self.data


class KwargsNode(Node):
def get(self, item: str, default: Any = None) -> Any:
return self[item] if item in self else default

def __getitem__(self, item: str) -> Any:
if item in self.model_fields:
return getattr(self, item)
else:
raise KeyError(item)

def __contains__(self, item: str) -> int:
return item in self.model_fields


class FileDescr(Node):
source: FileSource
"""∈📦 file source"""
Expand Down
4 changes: 2 additions & 2 deletions bioimageio/spec/model/v0_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
field_validator,
model_validator,
)
from typing_extensions import Annotated, LiteralString, Self, TypedDict, assert_never
from typing_extensions import Annotated, LiteralString, Self, assert_never

from bioimageio.spec._internal.base_nodes import FileDescr as FileDescr
from bioimageio.spec._internal.base_nodes import KwargsNode, Node, NodeWithExplicitlySetFields, StringNode
Expand Down Expand Up @@ -391,7 +391,7 @@ class TensorDescrBase(Node):
If not specified, the full data range that can be expressed in `data_type` is allowed."""


class ProcessingKwargs(TypedDict):
class ProcessingKwargs(KwargsNode):
"""base class for pre-/postprocessing key word arguments"""


Expand Down

0 comments on commit c6cd1c5

Please sign in to comment.