Added poetry integration.

Description:
* Fixed github actions;
* Removed requirements.txt;
* Fixed CONTRIBUTING.md;
* Fixed black and flake8.

Signed-off-by: Pavel <win10@list.ru>
This commit is contained in:
Pavel
2021-10-08 15:57:22 +04:00
parent 80c6ff38a1
commit b2541bed1e
52 changed files with 2685 additions and 377 deletions

View File

@ -19,6 +19,10 @@ snakes, and ormar(e) in italian which means cabinet.
And what's a better name for python ORM than snakes cabinet :)
"""
try:
from importlib import metadata
except ImportError: # pragma: no cover
import importlib_metadata as metadata # type: ignore
from ormar.protocols import QuerySetProtocol, RelationProtocol # noqa: I100
from ormar.decorators import ( # noqa: I100
post_delete,
@ -64,7 +68,7 @@ from ormar.fields import (
UUID,
UniqueColumns,
) # noqa: I100
from ormar.models import ExcludableItems, Model, Extra
from ormar.models import ExcludableItems, Extra, Model
from ormar.models.metaclass import ModelMeta
from ormar.queryset import OrderAction, QuerySet, and_, or_
from ormar.relations import RelationType
@ -78,7 +82,7 @@ class UndefinedType: # pragma no cover
Undefined = UndefinedType()
__version__ = "0.10.20"
__version__ = metadata.version("ormar")
__all__ = [
"Integer",
"BigInteger",

View File

@ -41,7 +41,7 @@ def receiver(
return _decorator
def post_save(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable:
def post_save(senders: Union[Type["Model"], List[Type["Model"]]]) -> Callable:
"""
Connect given function to all senders for post_save signal.
@ -54,7 +54,7 @@ def post_save(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable:
return receiver(signal="post_save", senders=senders)
def post_update(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable:
def post_update(senders: Union[Type["Model"], List[Type["Model"]]]) -> Callable:
"""
Connect given function to all senders for post_update signal.
@ -67,7 +67,7 @@ def post_update(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable
return receiver(signal="post_update", senders=senders)
def post_delete(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable:
def post_delete(senders: Union[Type["Model"], List[Type["Model"]]]) -> Callable:
"""
Connect given function to all senders for post_delete signal.
@ -80,7 +80,7 @@ def post_delete(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable
return receiver(signal="post_delete", senders=senders)
def pre_save(senders: Union[Type["Model"], List[Type["Model"]]],) -> Callable:
def pre_save(senders: Union[Type["Model"], List[Type["Model"]]]) -> Callable:
"""
Connect given function to all senders for pre_save signal.

View File

@ -5,7 +5,7 @@ Gathers all exceptions thrown by ormar.
class AsyncOrmException(Exception):
"""
Base ormar Exception
Base ormar Exception
"""
pass
@ -13,13 +13,13 @@ class AsyncOrmException(Exception):
class ModelDefinitionError(AsyncOrmException):
"""
Raised for errors related to the model definition itself:
Raised for errors related to the model definition itself:
* setting @property_field on method with arguments other than func(self)
* defining a Field without required parameters
* defining a model with more than one primary_key
* defining a model without primary_key
* setting primary_key column as pydantic_only
* setting @property_field on method with arguments other than func(self)
* defining a Field without required parameters
* defining a model with more than one primary_key
* defining a model without primary_key
* setting primary_key column as pydantic_only
"""
pass
@ -27,7 +27,7 @@ class ModelDefinitionError(AsyncOrmException):
class ModelError(AsyncOrmException):
"""
Raised for initialization of model with non-existing field keyword.
Raised for initialization of model with non-existing field keyword.
"""
pass
@ -35,7 +35,7 @@ class ModelError(AsyncOrmException):
class NoMatch(AsyncOrmException):
"""
Raised for database queries that has no matching result (empty result).
Raised for database queries that has no matching result (empty result).
"""
pass
@ -43,8 +43,8 @@ class NoMatch(AsyncOrmException):
class MultipleMatches(AsyncOrmException):
"""
Raised for database queries that should return one row (i.e. get, first etc.)
but has multiple matching results in response.
Raised for database queries that should return one row (i.e. get, first etc.)
but has multiple matching results in response.
"""
pass
@ -52,11 +52,11 @@ class MultipleMatches(AsyncOrmException):
class QueryDefinitionError(AsyncOrmException):
"""
Raised for errors in query definition:
Raised for errors in query definition:
* using contains or icontains filter with instance of the Model
* using Queryset.update() without filter and setting each flag to True
* using Queryset.delete() without filter and setting each flag to True
* using contains or icontains filter with instance of the Model
* using Queryset.update() without filter and setting each flag to True
* using Queryset.delete() without filter and setting each flag to True
"""
pass
@ -68,8 +68,8 @@ class RelationshipInstanceError(AsyncOrmException):
class ModelPersistenceError(AsyncOrmException):
"""
Raised for update of models without primary_key set (cannot retrieve from db)
or for saving a model with relation to unsaved model (cannot extract fk value).
Raised for update of models without primary_key set (cannot retrieve from db)
or for saving a model with relation to unsaved model (cannot extract fk value).
"""
pass
@ -77,7 +77,7 @@ class ModelPersistenceError(AsyncOrmException):
class SignalDefinitionError(AsyncOrmException):
"""
Raised when non callable receiver is passed as signal callback.
Raised when non callable receiver is passed as signal callback.
"""
pass

View File

@ -92,7 +92,7 @@ def create_dummy_model(
def populate_fk_params_based_on_to_model(
to: Type["T"], nullable: bool, onupdate: str = None, ondelete: str = None,
to: Type["T"], nullable: bool, onupdate: str = None, ondelete: str = None
) -> Tuple[Any, List, Any]:
"""
Based on target to model to which relation leads to populates the type of the
@ -347,9 +347,7 @@ class ForeignKeyField(BaseField):
"""
if self.to.__class__ == ForwardRef:
self.to = evaluate_forwardref(
self.to, # type: ignore
globalns,
localns or None,
self.to, globalns, localns or None # type: ignore
)
(
self.__type__,
@ -363,7 +361,7 @@ class ForeignKeyField(BaseField):
)
def _extract_model_from_sequence(
self, value: List, child: "Model", to_register: bool,
self, value: List, child: "Model", to_register: bool
) -> List["Model"]:
"""
Takes a list of Models and registers them on parent.
@ -382,13 +380,13 @@ class ForeignKeyField(BaseField):
"""
return [
self.expand_relationship( # type: ignore
value=val, child=child, to_register=to_register,
value=val, child=child, to_register=to_register
)
for val in value
]
def _register_existing_model(
self, value: "Model", child: "Model", to_register: bool,
self, value: "Model", child: "Model", to_register: bool
) -> "Model":
"""
Takes already created instance and registers it for parent.
@ -479,9 +477,7 @@ class ForeignKeyField(BaseField):
:param child: child model
:type child: Model class
"""
model._orm.add(
parent=model, child=child, field=self,
)
model._orm.add(parent=model, child=child, field=self)
def has_unresolved_forward_refs(self) -> bool:
"""

View File

@ -223,20 +223,16 @@ class ManyToManyField(ForeignKeyField, ormar.QuerySetProtocol, ormar.RelationPro
"""
if self.to.__class__ == ForwardRef:
self.to = evaluate_forwardref(
self.to, # type: ignore
globalns,
localns or None,
self.to, globalns, localns or None # type: ignore
)
(self.__type__, self.column_type,) = populate_m2m_params_based_on_to_model(
to=self.to, nullable=self.nullable,
(self.__type__, self.column_type) = populate_m2m_params_based_on_to_model(
to=self.to, nullable=self.nullable
)
if self.through.__class__ == ForwardRef:
self.through = evaluate_forwardref(
self.through, # type: ignore
globalns,
localns or None,
self.through, globalns, localns or None # type: ignore
)
forbid_through_relations(self.through)

View File

@ -254,9 +254,7 @@ class Text(ModelFieldFactory, str):
_type = str
_sample = "text"
def __new__( # type: ignore
cls, **kwargs: Any
) -> BaseField:
def __new__(cls, **kwargs: Any) -> BaseField: # type: ignore
kwargs = {
**kwargs,
**{

View File

@ -15,7 +15,7 @@ if TYPE_CHECKING: # pragma no cover
def Through( # noqa CFQ002
to: "ToType", *, name: str = None, related_name: str = None, **kwargs: Any,
to: "ToType", *, name: str = None, related_name: str = None, **kwargs: Any
) -> Any:
"""
Despite a name it's a function that returns constructed ThroughField.

View File

@ -29,7 +29,7 @@ def is_field_an_forward_ref(field: "BaseField") -> bool:
)
def populate_default_options_values(
def populate_default_options_values( # noqa: CCR001
new_model: Type["Model"], model_fields: Dict
) -> None:
"""

View File

@ -280,7 +280,7 @@ def copy_and_replace_m2m_through_model( # noqa: CFQ002
field.create_default_through_model()
through_class = field.through
new_meta: ormar.ModelMeta = type( # type: ignore
"Meta", (), dict(through_class.Meta.__dict__),
"Meta", (), dict(through_class.Meta.__dict__)
)
copy_name = through_class.__name__ + attrs.get("__name__", "")
copy_through = type(copy_name, (ormar.Model,), {"Meta": new_meta})
@ -566,9 +566,7 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
attrs, model_fields = extract_from_parents_definition(
base_class=base, curr_class=mcs, attrs=attrs, model_fields=model_fields
)
new_model = super().__new__( # type: ignore
mcs, name, bases, attrs
)
new_model = super().__new__(mcs, name, bases, attrs) # type: ignore
add_cached_properties(new_model)
@ -647,6 +645,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
access_chain=item,
)
return FieldAccessor(
source_model=cast(Type["Model"], self), field=field, access_chain=item,
source_model=cast(Type["Model"], self), field=field, access_chain=item
)
return object.__getattribute__(self, item)

View File

@ -141,7 +141,7 @@ class ExcludableMixin(RelationMixin):
return columns
@classmethod
def _update_excluded_with_related(cls, exclude: Union[Set, Dict, None],) -> Set:
def _update_excluded_with_related(cls, exclude: Union[Set, Dict, None]) -> Set:
"""
Used during generation of the dict().
To avoid cyclical references and max recurrence limit nested models have to

View File

@ -51,7 +51,7 @@ class PrefetchQueryMixin(RelationMixin):
@staticmethod
def get_column_name_for_id_extraction(
parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool,
parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool
) -> str:
"""
Returns name of the column that should be used to extract ids from model.

View File

@ -28,7 +28,7 @@ class PydanticMixin(RelationMixin):
@classmethod
def get_pydantic(
cls, *, include: Union[Set, Dict] = None, exclude: Union[Set, Dict] = None,
cls, *, include: Union[Set, Dict] = None, exclude: Union[Set, Dict] = None
) -> Type[pydantic.BaseModel]:
"""
Returns a pydantic model out of ormar model.

View File

@ -1,12 +1,4 @@
from typing import (
Callable,
Dict,
List,
Optional,
Set,
TYPE_CHECKING,
cast,
)
from typing import Callable, Dict, List, Optional, Set, TYPE_CHECKING, cast
from ormar import BaseField, ForeignKeyField
from ormar.models.traversible import NodeList

View File

@ -222,7 +222,7 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
@staticmethod
async def _upsert_through_model(
instance: "Model", previous_model: "Model", relation_field: "ForeignKeyField",
instance: "Model", previous_model: "Model", relation_field: "ForeignKeyField"
) -> None:
"""
Upsert through model for m2m relation.

View File

@ -1,13 +1,4 @@
from typing import (
Any,
Dict,
List,
Optional,
Set,
TYPE_CHECKING,
TypeVar,
Union,
)
from typing import Any, Dict, List, Optional, Set, TYPE_CHECKING, TypeVar, Union
import ormar.queryset # noqa I100
from ormar.exceptions import ModelPersistenceError, NoMatch

View File

@ -1,14 +1,4 @@
from typing import (
Any,
Dict,
List,
Optional,
TYPE_CHECKING,
Tuple,
Type,
Union,
cast,
)
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Tuple, Type, Union, cast
try:
from sqlalchemy.engine.result import ResultProxy
@ -293,7 +283,7 @@ class ModelRow(NewBaseModel):
"""
through_name = cls.Meta.model_fields[related].through.get_name()
through_child = cls._create_through_instance(
row=row, related=related, through_name=through_name, excludable=excludable,
row=row, related=related, through_name=through_name, excludable=excludable
)
if child.__class__ != proxy_source_model:
@ -378,7 +368,7 @@ class ModelRow(NewBaseModel):
:rtype: Dict
"""
selected_columns = cls.own_table_columns(
model=cls, excludable=excludable, alias=table_prefix, use_alias=False,
model=cls, excludable=excludable, alias=table_prefix, use_alias=False
)
column_prefix = table_prefix + "_" if table_prefix else ""

View File

@ -18,17 +18,17 @@ from typing import (
cast,
)
import databases
import pydantic
import sqlalchemy
from ormar.models.utils import Extra
from pydantic import BaseModel
try:
import orjson as json
except ImportError: # pragma: no cover
import json # type: ignore
import databases
import pydantic
import sqlalchemy
from pydantic import BaseModel
import ormar # noqa I100
from ormar.exceptions import ModelError, ModelPersistenceError
@ -154,7 +154,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
# register the columns models after initialization
for related in self.extract_related_names().union(self.extract_through_names()):
model_fields[related].expand_relationship(
new_kwargs.get(related), self, to_register=True,
new_kwargs.get(related), self, to_register=True
)
if hasattr(self, "_init_private_attributes"):
@ -218,7 +218,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
f"need to call update_forward_refs()."
)
def _process_kwargs(self, kwargs: Dict) -> Tuple[Dict, Dict]:
def _process_kwargs(self, kwargs: Dict) -> Tuple[Dict, Dict]: # noqa: CCR001
"""
Initializes nested models.
@ -261,7 +261,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
k,
self._convert_json(
k,
model_fields[k].expand_relationship(v, self, to_register=False,)
model_fields[k].expand_relationship(v, self, to_register=False)
if k in model_fields
else (v if k in pydantic_fields else model_fields[k]),
),
@ -315,7 +315,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
self,
"_orm",
RelationsManager(
related_fields=self.extract_related_fields(), owner=cast("Model", self),
related_fields=self.extract_related_fields(), owner=cast("Model", self)
),
)
@ -488,7 +488,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
@staticmethod
def _get_not_excluded_fields(
fields: Union[List, Set], include: Optional[Dict], exclude: Optional[Dict],
fields: Union[List, Set], include: Optional[Dict], exclude: Optional[Dict]
) -> List:
"""
Returns related field names applying on them include and exclude set.

View File

@ -57,7 +57,7 @@ class FilterAction(QueryAction):
Extracted in order to easily change table prefixes on complex relations.
"""
def __init__(self, filter_str: str, value: Any, model_cls: Type["Model"],) -> None:
def __init__(self, filter_str: str, value: Any, model_cls: Type["Model"]) -> None:
super().__init__(query_str=filter_str, model_cls=model_cls)
self.filter_value = value
self._escape_characters_in_clause()
@ -148,7 +148,7 @@ class FilterAction(QueryAction):
filter_value = self.filter_value
clause = getattr(self.column, op_attr)(filter_value)
clause = self._compile_clause(
clause, modifiers={"escape": "\\" if self.has_escaped_character else None},
clause, modifiers={"escape": "\\" if self.has_escaped_character else None}
)
return clause
@ -170,7 +170,7 @@ class FilterAction(QueryAction):
]
def _compile_clause(
self, clause: sqlalchemy.sql.expression.BinaryExpression, modifiers: Dict,
self, clause: sqlalchemy.sql.expression.BinaryExpression, modifiers: Dict
) -> sqlalchemy.sql.expression.TextClause:
"""
Compiles the clause to str using appropriate database dialect, replace columns

View File

@ -185,7 +185,7 @@ class QueryClause:
"""
def __init__(
self, model_cls: Type["Model"], filter_clauses: List, select_related: List,
self, model_cls: Type["Model"], filter_clauses: List, select_related: List
) -> None:
self._select_related = select_related[:]

View File

@ -1,14 +1,5 @@
from collections import OrderedDict
from typing import (
Any,
Dict,
List,
Optional,
TYPE_CHECKING,
Tuple,
Type,
cast,
)
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Tuple, Type, cast
import sqlalchemy
from sqlalchemy import text
@ -102,9 +93,7 @@ class SqlJoin:
"""
return self.next_model.Meta.table
def _on_clause(
self, previous_alias: str, from_clause: str, to_clause: str,
) -> text:
def _on_clause(self, previous_alias: str, from_clause: str, to_clause: str) -> text:
"""
Receives aliases and names of both ends of the join and combines them
into one text clause used in joins.
@ -140,12 +129,7 @@ class SqlJoin:
self._process_following_joins()
return (
self.used_aliases,
self.select_from,
self.columns,
self.sorted_orders,
)
return (self.used_aliases, self.select_from, self.columns, self.sorted_orders)
def _forward_join(self) -> None:
"""
@ -269,7 +253,7 @@ class SqlJoin:
new_part = target_field.default_target_field_name() # type: ignore
return new_part
def _process_join(self,) -> None: # noqa: CFQ002
def _process_join(self) -> None: # noqa: CFQ002
"""
Resolves to and from column names and table names.
@ -316,7 +300,7 @@ class SqlJoin:
def _set_default_primary_key_order_by(self) -> None:
for order_by in self.next_model.Meta.orders_by:
clause = ormar.OrderAction(
order_str=order_by, model_cls=self.next_model, alias=self.next_alias,
order_str=order_by, model_cls=self.next_model, alias=self.next_alias
)
self.sorted_orders[clause] = clause.get_text_clause()
@ -355,8 +339,7 @@ class SqlJoin:
model = self.target_field.to
else:
alias = self.alias_manager.resolve_relation_alias(
from_model=self.target_field.owner,
relation_name=self.target_field.name,
from_model=self.target_field.owner, relation_name=self.target_field.name
)
model = self.target_field.to

View File

@ -1,13 +1,4 @@
from typing import (
Dict,
List,
Sequence,
Set,
TYPE_CHECKING,
Tuple,
Type,
cast,
)
from typing import Dict, List, Sequence, Set, TYPE_CHECKING, Tuple, Type, cast
import ormar
from ormar.queryset.clause import QueryClause
@ -192,7 +183,7 @@ class PrefetchQuery:
return list_of_ids
def _extract_required_ids(
self, parent_model: Type["Model"], reverse: bool, related: str,
self, parent_model: Type["Model"], reverse: bool, related: str
) -> Set:
"""
Delegates extraction of the fields to either get ids from raw sql response
@ -210,10 +201,7 @@ class PrefetchQuery:
use_raw = parent_model.get_name() not in self.models
column_name = parent_model.get_column_name_for_id_extraction(
parent_model=parent_model,
reverse=reverse,
related=related,
use_raw=use_raw,
parent_model=parent_model, reverse=reverse, related=related, use_raw=use_raw
)
if use_raw:
@ -263,7 +251,7 @@ class PrefetchQuery:
related=related,
)
qryclause = QueryClause(
model_cls=clause_target, select_related=[], filter_clauses=[],
model_cls=clause_target, select_related=[], filter_clauses=[]
)
kwargs = {f"{filter_column}__in": ids}
filter_clauses, _ = qryclause.prepare_filter(_own_only=False, **kwargs)
@ -271,7 +259,7 @@ class PrefetchQuery:
return []
def _populate_nested_related(
self, model: "Model", prefetch_dict: Dict, orders_by: Dict,
self, model: "Model", prefetch_dict: Dict, orders_by: Dict
) -> "Model":
"""
Populates all related models children of parent model that are
@ -540,7 +528,7 @@ class PrefetchQuery:
)
def _update_already_loaded_rows( # noqa: CFQ002
self, target_field: "BaseField", prefetch_dict: Dict, orders_by: Dict,
self, target_field: "BaseField", prefetch_dict: Dict, orders_by: Dict
) -> None:
"""
Updates models that are already loaded, usually children of children.
@ -598,7 +586,7 @@ class PrefetchQuery:
for row in rows:
field_name = parent_model.get_related_field_name(target_field=target_field)
item = target_model.extract_prefixed_table_columns(
item={}, row=row, table_prefix=table_prefix, excludable=excludable,
item={}, row=row, table_prefix=table_prefix, excludable=excludable
)
item["__excluded__"] = target_model.get_names_to_exclude(
excludable=excludable, alias=exclude_prefix

View File

@ -111,7 +111,7 @@ class Query:
:rtype: sqlalchemy.sql.selectable.Select
"""
self_related_fields = self.model_cls.own_table_columns(
model=self.model_cls, excludable=self.excludable, use_alias=True,
model=self.model_cls, excludable=self.excludable, use_alias=True
)
self.columns = self.model_cls.Meta.alias_manager.prefixed_columns(
"", self.table, self_related_fields

View File

@ -247,7 +247,7 @@ class QuerySet(Generic[T]):
return self.model_meta.table
def build_select_expression(
self, limit: int = None, offset: int = None, order_bys: List = None,
self, limit: int = None, offset: int = None, order_bys: List = None
) -> sqlalchemy.sql.select:
"""
Constructs the actual database query used in the QuerySet.
@ -378,7 +378,7 @@ class QuerySet(Generic[T]):
]
related = sorted(list(set(list(self._select_related) + related)))
return self.rebuild_self(select_related=related,)
return self.rebuild_self(select_related=related)
def select_all(self, follow: bool = False) -> "QuerySet[T]":
"""
@ -404,7 +404,7 @@ class QuerySet(Generic[T]):
relations = list(self.model.extract_related_names())
if follow:
relations = self.model._iterate_related_models()
return self.rebuild_self(select_related=relations,)
return self.rebuild_self(select_related=relations)
def prefetch_related(
self, related: Union[List, str, FieldAccessor]
@ -434,7 +434,7 @@ class QuerySet(Generic[T]):
]
related = list(set(list(self._prefetch_related) + related))
return self.rebuild_self(prefetch_related=related,)
return self.rebuild_self(prefetch_related=related)
def fields(
self, columns: Union[List, str, Set, Dict], _is_exclude: bool = False
@ -490,7 +490,7 @@ class QuerySet(Generic[T]):
is_exclude=_is_exclude,
)
return self.rebuild_self(excludable=excludable,)
return self.rebuild_self(excludable=excludable)
def exclude_fields(self, columns: Union[List, str, Set, Dict]) -> "QuerySet[T]":
"""
@ -564,7 +564,7 @@ class QuerySet(Generic[T]):
]
order_bys = self.order_bys + [x for x in orders_by if x not in self.order_bys]
return self.rebuild_self(order_bys=order_bys,)
return self.rebuild_self(order_bys=order_bys)
async def values(
self,
@ -821,7 +821,7 @@ class QuerySet(Generic[T]):
limit_count = page_size
query_offset = (page - 1) * page_size
return self.rebuild_self(limit_count=limit_count, offset=query_offset,)
return self.rebuild_self(limit_count=limit_count, offset=query_offset)
def limit(self, limit_count: int, limit_raw_sql: bool = None) -> "QuerySet[T]":
"""
@ -838,7 +838,7 @@ class QuerySet(Generic[T]):
:rtype: QuerySet
"""
limit_raw_sql = self.limit_sql_raw if limit_raw_sql is None else limit_raw_sql
return self.rebuild_self(limit_count=limit_count, limit_raw_sql=limit_raw_sql,)
return self.rebuild_self(limit_count=limit_count, limit_raw_sql=limit_raw_sql)
def offset(self, offset: int, limit_raw_sql: bool = None) -> "QuerySet[T]":
"""
@ -855,7 +855,7 @@ class QuerySet(Generic[T]):
:rtype: QuerySet
"""
limit_raw_sql = self.limit_sql_raw if limit_raw_sql is None else limit_raw_sql
return self.rebuild_self(offset=offset, limit_raw_sql=limit_raw_sql,)
return self.rebuild_self(offset=offset, limit_raw_sql=limit_raw_sql)
async def first(self, *args: Any, **kwargs: Any) -> "T":
"""

View File

@ -221,13 +221,13 @@ def extract_nested_models( # noqa: CCR001
if select_dict[related] is not Ellipsis:
for sub_child in child:
extract_nested_models(
sub_child, target_model, select_dict[related], extracted,
sub_child, target_model, select_dict[related], extracted
)
else:
extracted.setdefault(target_model.get_name(), []).append(child)
if select_dict[related] is not Ellipsis:
extract_nested_models(
child, target_model, select_dict[related], extracted,
child, target_model, select_dict[related], extracted
)

View File

@ -99,7 +99,7 @@ class AliasManager:
return table.alias(f"{alias}_{table.name}")
def add_relation_type(
self, source_model: Type["Model"], relation_name: str, reverse_name: str = None,
self, source_model: Type["Model"], relation_name: str, reverse_name: str = None
) -> None:
"""
Registers the relations defined in ormar models.

View File

@ -294,7 +294,7 @@ class QuerysetProxy(Generic[T]):
:type fields: Union[List, str, Set, Dict]
"""
return await self.queryset.values(
fields=fields, exclude_through=exclude_through,
fields=fields, exclude_through=exclude_through
)
async def values_list(
@ -479,8 +479,7 @@ class QuerysetProxy(Generic[T]):
await child.update(**kwargs) # type: ignore
if self.type_ == ormar.RelationType.MULTIPLE and through_kwargs:
await self.update_through_instance(
child=child, # type: ignore
**through_kwargs,
child=child, **through_kwargs # type: ignore
)
return len(children)

View File

@ -57,7 +57,7 @@ class RelationsManager:
return None # pragma nocover
@staticmethod
def add(parent: "Model", child: "Model", field: "ForeignKeyField",) -> None:
def add(parent: "Model", child: "Model", field: "ForeignKeyField") -> None:
"""
Adds relation on both sides -> meaning on both child and parent models.
One side of the relation is always weakref proxy to avoid circular refs.
@ -73,7 +73,7 @@ class RelationsManager:
:param field: field with relation definition
:type field: ForeignKeyField
"""
(parent, child, child_name, to_name,) = get_relations_sides_and_names(
(parent, child, child_name, to_name) = get_relations_sides_and_names(
field, parent, child
)

View File

@ -8,7 +8,7 @@ if TYPE_CHECKING: # pragma no cover
def get_relations_sides_and_names(
to_field: ForeignKeyField, parent: "Model", child: "Model",
to_field: ForeignKeyField, parent: "Model", child: "Model"
) -> Tuple["Model", "Model", str, str]:
"""
Determines the names of child and parent relations names, as well as