Skip to content

Commit 3a8b565

Browse files
committed
run make style
1 parent 8cb6ba7 commit 3a8b565

2 files changed

Lines changed: 27 additions & 75 deletions

File tree

tortoise/fields/data.py

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ def __init__(
333333
stacklevel=2,
334334
)
335335
if index or db_index:
336-
raise ConfigurationError(
337-
"TextField can't be indexed, consider CharField"
338-
)
336+
raise ConfigurationError("TextField can't be indexed, consider CharField")
339337
elif db_index:
340338
raise ConfigurationError("TextField can't be indexed, consider CharField")
341339

@@ -431,9 +429,7 @@ def __init__(self, max_digits: int, decimal_places: int, **kwargs: Any) -> None:
431429
super().__init__(**kwargs)
432430
self.max_digits = max_digits
433431
self.decimal_places = decimal_places
434-
self.quant = Decimal(
435-
"1" if decimal_places == 0 else f"1.{('0' * decimal_places)}"
436-
)
432+
self.quant = Decimal("1" if decimal_places == 0 else f"1.{('0' * decimal_places)}")
437433

438434
def to_python_value(self, value: Any) -> Decimal | None:
439435
if value is not None:
@@ -458,9 +454,7 @@ def function_cast(self, term: Term) -> Term:
458454
DatetimeFieldQueryValueType = TypeVar(
459455
"DatetimeFieldQueryValueType", datetime.datetime, int, float, str
460456
)
461-
DateFieldQueryValueType = TypeVar(
462-
"DateFieldQueryValueType", datetime.date, int, float, str
463-
)
457+
DateFieldQueryValueType = TypeVar("DateFieldQueryValueType", datetime.date, int, float, str)
464458

465459

466460
class DatetimeField(Field[T_DATETIME], datetime.datetime):
@@ -510,9 +504,7 @@ def __init__(
510504
**kwargs: Unpack[FieldKwargs],
511505
) -> None: ...
512506

513-
def __init__(
514-
self, auto_now: bool = False, auto_now_add: bool = False, **kwargs: Any
515-
) -> None:
507+
def __init__(self, auto_now: bool = False, auto_now_add: bool = False, **kwargs: Any) -> None:
516508
if auto_now_add and auto_now:
517509
raise ConfigurationError("You can choose only 'auto_now' or 'auto_now_add'")
518510
super().__init__(**kwargs)
@@ -652,9 +644,7 @@ def __init__(
652644
**kwargs: Unpack[FieldKwargs],
653645
) -> None: ...
654646

655-
def __init__(
656-
self, auto_now: bool = False, auto_now_add: bool = False, **kwargs: Any
657-
) -> None:
647+
def __init__(self, auto_now: bool = False, auto_now_add: bool = False, **kwargs: Any) -> None:
658648
if auto_now_add and auto_now:
659649
raise ConfigurationError("You can choose only 'auto_now' or 'auto_now_add'")
660650
super().__init__(**kwargs)
@@ -753,9 +743,7 @@ def to_db_value(
753743

754744
if value is None:
755745
return None
756-
return (
757-
(value.days * 86400000000) + (value.seconds * 1000000) + value.microseconds
758-
)
746+
return (value.days * 86400000000) + (value.seconds * 1000000) + value.microseconds
759747

760748

761749
class FloatField(Field[T_FLOAT], float):
@@ -919,9 +907,7 @@ def __init__(
919907
) -> None: ...
920908

921909
def __init__(self, **kwargs: Any) -> None:
922-
if (
923-
kwargs.get("primary_key") or kwargs.get("pk", False)
924-
) and "default" not in kwargs:
910+
if (kwargs.get("primary_key") or kwargs.get("pk", False)) and "default" not in kwargs:
925911
kwargs["default"] = uuid4
926912
super().__init__(**kwargs)
927913

@@ -996,9 +982,7 @@ def __init__(
996982

997983
# Automatic description for the field if not specified by the user
998984
if description is None:
999-
description = "\n".join([f"{e.name}: {int(e.value)}" for e in enum_type])[
1000-
:2048
1001-
]
985+
description = "\n".join([f"{e.name}: {int(e.value)}" for e in enum_type])[:2048]
1002986

1003987
super().__init__(description=description, **kwargs)
1004988
self.enum_type = enum_type
@@ -1007,9 +991,7 @@ def to_python_value(self, value: int | None) -> IntEnum | None:
1007991
value = self.enum_type(value) if value is not None else None
1008992
return value
1009993

1010-
def to_db_value(
1011-
self, value: IntEnum | None | int, instance: type[Model] | Model
1012-
) -> int | None:
994+
def to_db_value(self, value: IntEnum | None | int, instance: type[Model] | Model) -> int | None:
1013995
if isinstance(value, IntEnum):
1014996
value = int(value.value)
1015997
if isinstance(value, int):
@@ -1056,9 +1038,7 @@ def __init__(
10561038
) -> None:
10571039
# Automatic description for the field if not specified by the user
10581040
if description is None:
1059-
description = "\n".join([f"{e.name}: {str(e.value)}" for e in enum_type])[
1060-
:2048
1061-
]
1041+
description = "\n".join([f"{e.name}: {str(e.value)}" for e in enum_type])[:2048]
10621042

10631043
# Automatic CharField max_length
10641044
if max_length == 0:
@@ -1073,9 +1053,7 @@ def __init__(
10731053
def to_python_value(self, value: str | None) -> Enum | None:
10741054
return self.enum_type(value) if value is not None else None
10751055

1076-
def to_db_value(
1077-
self, value: Enum | None | str, instance: type[Model] | Model
1078-
) -> str | None:
1056+
def to_db_value(self, value: Enum | None | str, instance: type[Model] | Model) -> str | None:
10791057
self.validate(value)
10801058
if isinstance(value, Enum):
10811059
return str(value.value)

tortoise/fields/relational.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def offset(self, offset: int) -> QuerySet[MODEL]:
133133
"""
134134
return self._query.offset(offset)
135135

136-
async def create(
137-
self, using_db: BaseDBAsyncClient | None = None, **kwargs: Any
138-
) -> MODEL:
136+
async def create(self, using_db: BaseDBAsyncClient | None = None, **kwargs: Any) -> MODEL:
139137
"""
140138
Create a related record in the DB and returns the object, automatically setting the
141139
foreign key relationship to the parent instance.
@@ -167,9 +165,7 @@ async def create(
167165
# Call remote model's create method
168166
return await self.remote_model.create(using_db=using_db, **kwargs)
169167

170-
def _set_result_for_query(
171-
self, sequence: list[MODEL], attr: str | None = None
172-
) -> None:
168+
def _set_result_for_query(self, sequence: list[MODEL], attr: str | None = None) -> None:
173169
self._fetched = True
174170
self.related_objects = sequence
175171
if attr:
@@ -187,18 +183,12 @@ class ManyToManyRelation(ReverseRelation[MODEL]):
187183
Many-to-many relation container for :func:`.ManyToManyField`.
188184
"""
189185

190-
def __init__(
191-
self, instance: Model, m2m_field: ManyToManyFieldInstance[MODEL]
192-
) -> None:
193-
super().__init__(
194-
m2m_field.related_model, m2m_field.related_name, instance, "pk"
195-
)
186+
def __init__(self, instance: Model, m2m_field: ManyToManyFieldInstance[MODEL]) -> None:
187+
super().__init__(m2m_field.related_model, m2m_field.related_name, instance, "pk")
196188
self.field = m2m_field
197189
self.instance = instance
198190

199-
async def add(
200-
self, *instances: MODEL, using_db: BaseDBAsyncClient | None = None
201-
) -> None:
191+
async def add(self, *instances: MODEL, using_db: BaseDBAsyncClient | None = None) -> None:
202192
"""
203193
Adds one or more of ``instances`` to the relation.
204194
@@ -217,9 +207,7 @@ async def add(
217207
pks_f: list = []
218208
for instance_to_add in instances:
219209
if not instance_to_add._saved_in_db:
220-
raise OperationalError(
221-
f"You should first call .save() on {instance_to_add}"
222-
)
210+
raise OperationalError(f"You should first call .save() on {instance_to_add}")
223211
pk_f = related_pk_formatting_func(instance_to_add.pk, instance_to_add)
224212
pks_f.append(pk_f)
225213
through_table = Table(self.field.through, schema=self.field.through_schema)
@@ -229,13 +217,9 @@ async def add(
229217
through_table[forward_key],
230218
)
231219
select_query = (
232-
db.query_class.from_(through_table)
233-
.where(backward_field == pk_b)
234-
.select(forward_key)
235-
)
236-
criterion = (
237-
forward_field == pks_f[0] if len(pks_f) == 1 else forward_field.isin(pks_f)
220+
db.query_class.from_(through_table).where(backward_field == pk_b).select(forward_key)
238221
)
222+
criterion = forward_field == pks_f[0] if len(pks_f) == 1 else forward_field.isin(pks_f)
239223
select_query = select_query.where(criterion)
240224

241225
_, already_existing_relations_raw = await db.execute_query(
@@ -247,9 +231,7 @@ async def add(
247231
}
248232

249233
if pks_f_to_insert := set(pks_f) - already_existing_forward_pks:
250-
query = db.query_class.into(through_table).columns(
251-
forward_field, backward_field
252-
)
234+
query = db.query_class.into(through_table).columns(forward_field, backward_field)
253235
for pk_f in pks_f_to_insert:
254236
query = query.insert(pk_f, pk_b)
255237
await db.execute_query(*query.get_parameterized_sql())
@@ -260,9 +242,7 @@ async def clear(self, using_db: BaseDBAsyncClient | None = None) -> None:
260242
"""
261243
await self._remove_or_clear(using_db=using_db)
262244

263-
async def remove(
264-
self, *instances: MODEL, using_db: BaseDBAsyncClient | None = None
265-
) -> None:
245+
async def remove(self, *instances: MODEL, using_db: BaseDBAsyncClient | None = None) -> None:
266246
"""
267247
Removes one or more of ``instances`` from the relation.
268248
@@ -287,9 +267,9 @@ async def _remove_or_clear(
287267
if instances:
288268
related_pk_formatting_func = type(instances[0])._meta.pk.to_db_value
289269
if len(instances) == 1:
290-
condition &= through_table[
291-
self.field.forward_key
292-
] == related_pk_formatting_func(instances[0].pk, instances[0])
270+
condition &= through_table[self.field.forward_key] == related_pk_formatting_func(
271+
instances[0].pk, instances[0]
272+
)
293273
else:
294274
condition &= through_table[self.field.forward_key].isin(
295275
[related_pk_formatting_func(i.pk, i) for i in instances]
@@ -317,9 +297,7 @@ def __init__(
317297
if TYPE_CHECKING:
318298

319299
@overload
320-
def __get__(
321-
self, instance: None, owner: type[Model]
322-
) -> RelationalField[MODEL]: ...
300+
def __get__(self, instance: None, owner: type[Model]) -> RelationalField[MODEL]: ...
323301

324302
@overload
325303
def __get__(self, instance: Model, owner: type[Model]) -> MODEL: ...
@@ -348,9 +326,7 @@ def validate_model_name(cls, model_name: str | type[Model]) -> None:
348326
) from None
349327
elif len(model_name.split(".")) != 2:
350328
field_type = cls.__name__.replace("Instance", "")
351-
raise ConfigurationError(
352-
f'{field_type} accepts model name in format "app.Model"'
353-
)
329+
raise ConfigurationError(f'{field_type} accepts model name in format "app.Model"')
354330

355331

356332
class ForeignKeyFieldInstance(RelationalField[MODEL]):
@@ -370,9 +346,7 @@ def __init__(
370346
"on_delete can only be CASCADE, RESTRICT, SET_NULL, SET_DEFAULT or NO_ACTION"
371347
)
372348
if on_delete == SET_NULL and not bool(kwargs.get("null")):
373-
raise ConfigurationError(
374-
"If on_delete is SET_NULL, then field must have null=True set"
375-
)
349+
raise ConfigurationError("If on_delete is SET_NULL, then field must have null=True set")
376350
self.on_delete = on_delete
377351

378352
def describe(self, serializable: bool) -> dict:

0 commit comments

Comments
 (0)