Source code for ebonite.core.objects.typing

from abc import abstractmethod
from typing import Union

from pyjackson.core import ArgList, Field
from pyjackson.generics import Serializer


[docs]class TypeWithSpec(Serializer): """ Abstract base class for types providing its OpenAPI schema definition """
[docs] @abstractmethod def get_spec(self) -> ArgList: pass # pragma: no cover
[docs] def is_list(self): return False
[docs] @abstractmethod def list_size(self): pass # pragma: no cover
[docs]class ListTypeWithSpec(TypeWithSpec): """ Abstract base class for `list`-like types providing its OpenAPI schema definition """
[docs] def is_list(self): return True
[docs] @abstractmethod def list_size(self): return NotImplementedError # pragma: no cover
[docs]class SizedTypedListType(ListTypeWithSpec): """ Subclass of :class:`ListTypeWithSpec` which specifies size of internal `list` """ def __init__(self, size: Union[int, None], dtype: type): self.dtype = dtype self.size = size
[docs] def get_spec(self) -> ArgList: return [Field(0, self.dtype, False)]
[docs] def list_size(self): return self.size
[docs] @abstractmethod def deserialize(self, obj): raise NotImplementedError # pragma: no cover
[docs] @abstractmethod def serialize(self, instance): raise NotImplementedError # pragma: no cover