Coverage for tortoise_serializer/protocols.py: 100%
20 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 19:39 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 19:39 +0200
1from typing import (
2 Any,
3 Awaitable,
4 Callable,
5 Generator,
6 Protocol,
7 Self,
8 Sequence,
9 Type,
10 runtime_checkable,
11)
13from pydantic.main import IncEx
14from tortoise import Model
15from tortoise.queryset import QuerySet
17from .types import MODEL, ContextType
20@runtime_checkable
21class SerializerProtocol(Protocol):
22 @classmethod
23 async def from_tortoise_orm(
24 cls,
25 instance: Model,
26 computed_fields: dict[str, Callable[[Model, Any], Awaitable[Any]]]
27 | None = None,
28 context: dict[str, Any] | ContextType | None = None,
29 ) -> Self: ...
31 @classmethod
32 async def from_tortoise_instances(
33 cls, instances: Sequence[Model], **kwargs
34 ) -> list[Self]: ...
36 @classmethod
37 async def from_queryset(
38 cls, queryset: QuerySet, *args, **kwargs
39 ) -> list[Self]: ...
41 def partial_update_tortoise_instance(
42 self, model: Model, **kwargs
43 ) -> bool: ...
45 async def create_tortoise_instance(
46 self,
47 model: Type[MODEL],
48 _exclude: IncEx | None = None,
49 **kwargs,
50 ) -> MODEL: ...
52 @classmethod
53 def get_prefetch_fields_generator(
54 cls, prefix: str = ""
55 ) -> Generator[str, None, None]: ...
57 @classmethod
58 def get_prefetch_fields(cls, prefix: str = "") -> list[str]: ...
60 def has_been_set(self, field_name: str) -> bool: ...