refactor many2many typehints into protocols

This commit is contained in:
collerek
2020-11-01 08:29:06 +01:00
parent 79cf225ddc
commit 9175f6004c
6 changed files with 66 additions and 62 deletions

View File

@ -0,0 +1,4 @@
from ormar.protocols.queryset_protocol import QuerySetProtocol
from ormar.protocols.relation_protocol import RelationProtocol
__all__ = ["QuerySetProtocol", "RelationProtocol"]

View File

@ -0,0 +1,41 @@
from typing import Any, List, Optional, Protocol, Sequence, TYPE_CHECKING, Union
if TYPE_CHECKING: # noqa: C901; #pragma nocover
from ormar import QuerySet, Model
class QuerySetProtocol(Protocol): # pragma: nocover
def filter(self, **kwargs: Any) -> "QuerySet": # noqa: A003, A001
...
def select_related(self, related: Union[List, str]) -> "QuerySet":
...
async def exists(self) -> bool:
...
async def count(self) -> int:
...
async def clear(self) -> int:
...
def limit(self, limit_count: int) -> "QuerySet":
...
def offset(self, offset: int) -> "QuerySet":
...
async def first(self, **kwargs: Any) -> "Model":
...
async def get(self, **kwargs: Any) -> "Model":
...
async def all( # noqa: A003, A001
self, **kwargs: Any
) -> Sequence[Optional["Model"]]:
...
async def create(self, **kwargs: Any) -> "Model":
...

View File

@ -0,0 +1,12 @@
from typing import Protocol, TYPE_CHECKING, Type, Union
if TYPE_CHECKING: # pragma: nocover
from ormar import Model
class RelationProtocol(Protocol): # pragma: nocover
def add(self, child: "Model") -> None:
...
def remove(self, child: Union["Model", Type["Model"]]) -> None:
...