Skip to content

Commit

Permalink
remove another dict
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jan 3, 2025
1 parent d5b514b commit a1896fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
27 changes: 11 additions & 16 deletions src/ome_types/_mixins/_kinded.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import builtins
from typing import Any
from typing import TYPE_CHECKING, Any

from pydantic import BaseModel

try:
from pydantic import model_serializer
except ImportError:
model_serializer = None # type: ignore
from pydantic import BaseModel, model_serializer


class KindMixin(BaseModel):
Expand All @@ -20,15 +15,15 @@ def __init__(self, **data: Any) -> None:
data.pop("kind", None)
return super().__init__(**data)

def dict(self, **kwargs: Any) -> dict[str, Any]:
d = super().dict(**kwargs)
d["kind"] = self.__class__.__name__.lower()
return d

if model_serializer is not None:
if not TYPE_CHECKING:

@model_serializer(mode="wrap")
def serialize_root(self, handler, _info) -> builtins.dict: # type: ignore
d = handler(self)
def model_dump(self, **kwargs: Any) -> dict[str, Any]:
d = super().model_dump(**kwargs)

Check warning on line 21 in src/ome_types/_mixins/_kinded.py

View check run for this annotation

Codecov / codecov/patch

src/ome_types/_mixins/_kinded.py#L21

Added line #L21 was not covered by tests
d["kind"] = self.__class__.__name__.lower()
return d

@model_serializer(mode="wrap")
def serialize_root(self, handler, _info) -> builtins.dict: # type: ignore
d = handler(self)
d["kind"] = self.__class__.__name__.lower()
return d
18 changes: 7 additions & 11 deletions src/ome_types/_mixins/_map_mixin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from collections.abc import Iterator, MutableMapping
from typing import TYPE_CHECKING, Any, Optional

try:
from pydantic import model_serializer
except ImportError:
model_serializer = None # type: ignore

from pydantic import model_serializer

if TYPE_CHECKING:
from typing import Protocol
Expand Down Expand Up @@ -45,11 +41,11 @@ def __setitem__(self: "HasMsProtocol", key: str, value: Optional[str]) -> None:
def _pydict(self: "HasMsProtocol", **kwargs: Any) -> dict[str, str]:
return {m.k: m.value for m in self.ms if m.k is not None}

def dict(self, **kwargs: Any) -> dict[str, Any]:
return self._pydict() # type: ignore

if model_serializer is not None:
if not TYPE_CHECKING:

@model_serializer(mode="wrap")
def serialize_root(self, handler, _info) -> dict: # type: ignore
def model_dump(self, **kwargs: Any) -> dict[str, Any]:
return self._pydict() # type: ignore

@model_serializer(mode="wrap")
def serialize_root(self, handler, _info) -> dict: # type: ignore
return self._pydict() # type: ignore

0 comments on commit a1896fc

Please sign in to comment.