refactor many2many typehints into protocols
This commit is contained in:
4
ormar/protocols/__init__.py
Normal file
4
ormar/protocols/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
from ormar.protocols.queryset_protocol import QuerySetProtocol
|
||||
from ormar.protocols.relation_protocol import RelationProtocol
|
||||
|
||||
__all__ = ["QuerySetProtocol", "RelationProtocol"]
|
||||
41
ormar/protocols/queryset_protocol.py
Normal file
41
ormar/protocols/queryset_protocol.py
Normal 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":
|
||||
...
|
||||
12
ormar/protocols/relation_protocol.py
Normal file
12
ormar/protocols/relation_protocol.py
Normal 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:
|
||||
...
|
||||
Reference in New Issue
Block a user