Skip to content

Commit

Permalink
Use ruff format instead of black (#962)
Browse files Browse the repository at this point in the history
* use ruff format only instead of black

* fix ruff issues
  • Loading branch information
roman-right authored Jul 3, 2024
1 parent 6989a1d commit ff709bf
Show file tree
Hide file tree
Showing 36 changed files with 187 additions and 220 deletions.
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
repos:
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
language_version: python3.10
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.290
rev: v0.5.0
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.10.1
hooks:
- id: mypy
additional_dependencies:
Expand Down
12 changes: 6 additions & 6 deletions beanie/migrations/controllers/iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ def __init__(self, function):
)
if input_signature is None:
raise RuntimeError("input_signature must not be None")
self.input_document_model: Type[
Document
] = input_signature.annotation
self.input_document_model: Type[Document] = (
input_signature.annotation
)
output_signature = self.function_signature.parameters.get(
"output_document"
)
if output_signature is None:
raise RuntimeError("output_signature must not be None")
self.output_document_model: Type[
Document
] = output_signature.annotation
self.output_document_model: Type[Document] = (
output_signature.annotation
)

if (
not isclass(self.input_document_model)
Expand Down
3 changes: 2 additions & 1 deletion beanie/migrations/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ async def build(cls, path: Path):

db = DBHandler.get_db()
await init_beanie(
database=db, document_models=[MigrationLog] # type: ignore
database=db,
document_models=[MigrationLog], # type: ignore
)
current_migration = await MigrationLog.find_one({"is_current": True})

Expand Down
6 changes: 2 additions & 4 deletions beanie/migrations/template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class Forward:
...
class Forward: ...


class Backward:
...
class Backward: ...
4 changes: 2 additions & 2 deletions beanie/odm/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def decorator(f: F) -> F:


def before_event(
*args: Union[List[EventTypes], EventTypes]
*args: Union[List[EventTypes], EventTypes],
) -> Callable[[F], F]:
"""
Decorator. It adds action, which should run before mentioned one
Expand All @@ -189,7 +189,7 @@ def before_event(


def after_event(
*args: Union[List[EventTypes], EventTypes]
*args: Union[List[EventTypes], EventTypes],
) -> Callable[[F], F]:
"""
Decorator. It adds action, which should run after mentioned one
Expand Down
4 changes: 3 additions & 1 deletion beanie/odm/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ async def commit(self) -> Optional[BulkWriteResult]:
query = op.operation(op.first_query, **op.pymongo_kwargs) # type: ignore
else:
query = op.operation(
op.first_query, op.second_query, **op.pymongo_kwargs # type: ignore
op.first_query,
op.second_query,
**op.pymongo_kwargs, # type: ignore
)
requests.append(query)

Expand Down
20 changes: 13 additions & 7 deletions beanie/odm/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def __get_pydantic_core_schema__(

@classmethod
def __get_pydantic_json_schema__(
cls, schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler # type: ignore
cls,
schema: core_schema.CoreSchema,
handler: GetJsonSchemaHandler, # type: ignore
) -> JsonSchemaValue:
json_schema = handler(schema)
json_schema.update(
Expand Down Expand Up @@ -187,9 +189,9 @@ def __modify_schema__(cls, field_schema):


if not IS_PYDANTIC_V2:
ENCODERS_BY_TYPE[
PydanticObjectId
] = str # it is a workaround to force pydantic make json schema for this field
ENCODERS_BY_TYPE[PydanticObjectId] = (
str # it is a workaround to force pydantic make json schema for this field
)

BeanieObjectId = PydanticObjectId

Expand Down Expand Up @@ -336,7 +338,7 @@ async def fetch_list(

@staticmethod
def repack_links(
links: List[Union["Link", "DocType"]]
links: List[Union["Link", "DocType"]],
) -> OrderedDictType[Any, Any]:
result = OrderedDict()
for link in links:
Expand Down Expand Up @@ -364,7 +366,9 @@ def serialize(value: Union["Link", BaseModel]):
@classmethod
def build_validation(cls, handler, source_type):
def validate(v: Union[DBRef, T], validation_info: ValidationInfo):
document_class = DocsRegistry.evaluate_fr(get_args(source_type)[0]) # type: ignore # noqa: F821
document_class = DocsRegistry.evaluate_fr(
get_args(source_type)[0]
) # type: ignore # noqa: F821

if isinstance(v, DBRef):
return cls(ref=v, document_class=document_class)
Expand Down Expand Up @@ -463,7 +467,9 @@ def __init__(self, document_class: Type[T]):
@classmethod
def build_validation(cls, handler, source_type):
def validate(v: Union[DBRef, T], field):
document_class = DocsRegistry.evaluate_fr(get_args(source_type)[0]) # type: ignore # noqa: F821
document_class = DocsRegistry.evaluate_fr(
get_args(source_type)[0]
) # type: ignore # noqa: F821
if isinstance(v, dict) or isinstance(v, BaseModel):
return parse_obj(document_class, v)
return cls(document_class=document_class)
Expand Down
6 changes: 2 additions & 4 deletions beanie/odm/interfaces/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def aggregate(
session: Optional[ClientSession] = None,
ignore_cache: bool = False,
**pymongo_kwargs,
) -> AggregationQuery[Dict[str, Any]]:
...
) -> AggregationQuery[Dict[str, Any]]: ...

@overload
@classmethod
Expand All @@ -38,8 +37,7 @@ def aggregate(
session: Optional[ClientSession] = None,
ignore_cache: bool = False,
**pymongo_kwargs,
) -> AggregationQuery[DocumentProjectionType]:
...
) -> AggregationQuery[DocumentProjectionType]: ...

@classmethod
def aggregate(
Expand Down
3 changes: 1 addition & 2 deletions beanie/odm/interfaces/aggregation_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def aggregate(
projection_model=None,
session=None,
ignore_cache: bool = False,
):
...
): ...

async def sum(
self,
Expand Down
34 changes: 11 additions & 23 deletions beanie/odm/interfaces/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def find_one( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindOne[FindType]:
...
) -> FindOne[FindType]: ...

@overload
@classmethod
Expand All @@ -82,8 +81,7 @@ def find_one( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindOne["DocumentProjectionType"]:
...
) -> FindOne["DocumentProjectionType"]: ...

@classmethod
def find_one( # type: ignore
Expand Down Expand Up @@ -139,8 +137,7 @@ def find_many( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany[FindType]:
...
) -> FindMany[FindType]: ...

@overload
@classmethod
Expand All @@ -159,8 +156,7 @@ def find_many( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany["DocumentProjectionType"]:
...
) -> FindMany["DocumentProjectionType"]: ...

@classmethod
def find_many( # type: ignore
Expand Down Expand Up @@ -227,8 +223,7 @@ def find( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany[FindType]:
...
) -> FindMany[FindType]: ...

@overload
@classmethod
Expand All @@ -247,8 +242,7 @@ def find( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany["DocumentProjectionType"]:
...
) -> FindMany["DocumentProjectionType"]: ...

@classmethod
def find( # type: ignore
Expand Down Expand Up @@ -301,8 +295,7 @@ def find_all( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany[FindType]:
...
) -> FindMany[FindType]: ...

@overload
@classmethod
Expand All @@ -319,8 +312,7 @@ def find_all( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany["DocumentProjectionType"]:
...
) -> FindMany["DocumentProjectionType"]: ...

@classmethod
def find_all( # type: ignore
Expand Down Expand Up @@ -378,8 +370,7 @@ def all( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany[FindType]:
...
) -> FindMany[FindType]: ...

@overload
@classmethod
Expand All @@ -396,8 +387,7 @@ def all( # type: ignore
nesting_depth: Optional[int] = None,
nesting_depths_per_field: Optional[Dict[str, int]] = None,
**pymongo_kwargs,
) -> FindMany["DocumentProjectionType"]:
...
) -> FindMany["DocumentProjectionType"]: ...

@classmethod
def all( # type: ignore
Expand Down Expand Up @@ -472,9 +462,7 @@ def _add_class_id_filter(cls, args: Tuple, with_children: bool = False):
if cls.get_settings().union_doc:
args += (
{
cls.get_settings()
.class_id: cls.get_settings()
.union_doc_alias
cls.get_settings().class_id: cls.get_settings().union_doc_alias
},
)
return args
3 changes: 1 addition & 2 deletions beanie/odm/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class BaseOperator(Mapping):

@property
@abstractmethod
def query(self) -> MappingType[str, Any]:
...
def query(self) -> MappingType[str, Any]: ...

def __getitem__(self, item: str):
return self.query[item]
Expand Down
3 changes: 1 addition & 2 deletions beanie/odm/operators/find/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
from beanie.odm.operators import BaseOperator


class BaseFindOperator(BaseOperator, ABC):
...
class BaseFindOperator(BaseOperator, ABC): ...
3 changes: 1 addition & 2 deletions beanie/odm/operators/find/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from beanie.odm.operators.find import BaseFindOperator


class BaseFindArrayOperator(BaseFindOperator, ABC):
...
class BaseFindArrayOperator(BaseFindOperator, ABC): ...


class All(BaseFindArrayOperator):
Expand Down
3 changes: 1 addition & 2 deletions beanie/odm/operators/find/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from beanie.odm.operators.find import BaseFindOperator


class BaseFindElementOperator(BaseFindOperator, ABC):
...
class BaseFindElementOperator(BaseFindOperator, ABC): ...


class Exists(BaseFindElementOperator):
Expand Down
3 changes: 1 addition & 2 deletions beanie/odm/operators/find/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from beanie.odm.operators.find import BaseFindOperator


class BaseFindEvaluationOperator(BaseFindOperator, ABC):
...
class BaseFindEvaluationOperator(BaseFindOperator, ABC): ...


class Expr(BaseFindEvaluationOperator):
Expand Down
15 changes: 7 additions & 8 deletions beanie/odm/operators/find/geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from beanie.odm.operators.find import BaseFindOperator


class BaseFindGeospatialOperator(BaseFindOperator, ABC):
...
class BaseFindGeospatialOperator(BaseFindOperator, ABC): ...


class GeoIntersects(BaseFindGeospatialOperator):
Expand Down Expand Up @@ -260,13 +259,13 @@ def query(self):
}
}
if self.max_distance:
expression[self.field][self.operator][
"$maxDistance"
] = self.max_distance # type: ignore
expression[self.field][self.operator]["$maxDistance"] = (
self.max_distance
) # type: ignore
if self.min_distance:
expression[self.field][self.operator][
"$minDistance"
] = self.min_distance # type: ignore
expression[self.field][self.operator]["$minDistance"] = (
self.min_distance
) # type: ignore
return expression


Expand Down
3 changes: 1 addition & 2 deletions beanie/odm/operators/find/logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
from beanie.odm.operators.find import BaseFindOperator


class BaseFindLogicalOperator(BaseFindOperator, ABC):
...
class BaseFindLogicalOperator(BaseFindOperator, ABC): ...


class LogicalOperatorForListOfExpressions(BaseFindLogicalOperator):
Expand Down
3 changes: 1 addition & 2 deletions beanie/odm/operators/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@
class BaseUpdateOperator(BaseOperator):
@property
@abstractmethod
def query(self) -> Mapping[str, Any]:
...
def query(self) -> Mapping[str, Any]: ...
3 changes: 1 addition & 2 deletions beanie/odm/operators/update/bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from beanie.odm.operators.update import BaseUpdateOperator


class BaseUpdateBitwiseOperator(BaseUpdateOperator, ABC):
...
class BaseUpdateBitwiseOperator(BaseUpdateOperator, ABC): ...


class Bit(BaseUpdateBitwiseOperator):
Expand Down
Loading

0 comments on commit ff709bf

Please sign in to comment.