Skip to content

Commit 00af927

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent f9720bb commit 00af927

File tree

18 files changed

+29
-100
lines changed

18 files changed

+29
-100
lines changed

django_sorcery/db/fields.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,11 @@ def get_django_dialect_ranges(self):
263263
ops = operations.BaseDatabaseOperations
264264
with suppress(ImportError):
265265
ops = (
266-
import_string(
267-
f"{DIALECT_MAP_TO_DJANGO.get(self.db.url.get_dialect().name)}.base.DatabaseOperations"
268-
)
266+
import_string(f"{DIALECT_MAP_TO_DJANGO.get(self.db.url.get_dialect().name)}.base.DatabaseOperations")
269267
if self.db
270268
else operations.BaseDatabaseOperations
271269
)
272270

273-
274271
return ops.integer_field_ranges
275272

276273
def get_dialect_range(self):

django_sorcery/db/meta/model.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,7 @@ def __repr__(self):
150150
reprs = ["<model_info({!s})>".format(self.model_class.__name__)]
151151
reprs.extend(f" {repr(i)}" for i in self.primary_keys.values())
152152
reprs.extend(f" {repr(i)}" for _, i in sorted(self.properties.items()))
153-
reprs.extend(
154-
f" {i}"
155-
for i in chain(
156-
*[repr(c).split("\n") for _, c in sorted(self.composites.items())]
157-
)
158-
)
153+
reprs.extend(f" {i}" for i in chain(*[repr(c).split("\n") for _, c in sorted(self.composites.items())]))
159154

160155
reprs.extend(f" {repr(i)}" for _, i in sorted(self.relationships.items()))
161156
return "\n".join(reprs)

django_sorcery/db/meta/relations.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ def __init__(self, relationship):
5555
self.local_remote_pairs_for_identity_key = []
5656
try:
5757
# ensure local_remote pairs are of same order as remote pk
58-
self.local_remote_pairs_for_identity_key.extend(
59-
(pairs[i], i) for i in target_pk
60-
)
58+
self.local_remote_pairs_for_identity_key.extend((pairs[i], i) for i in target_pk)
6159

6260
except KeyError:
6361
# if relation is missing one of related pk columns
@@ -80,9 +78,7 @@ def __init__(self, relationship):
8078

8179
if len(matching_constraints) == 1:
8280
pairs = {i.column: i.parent for i in matching_constraints[0].elements}
83-
self.local_remote_pairs_for_identity_key.extend(
84-
(pairs[i], i) for i in target_pk
85-
)
81+
self.local_remote_pairs_for_identity_key.extend((pairs[i], i) for i in target_pk)
8682

8783
else:
8884
# if everything fails, return default pairs

django_sorcery/db/query.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,13 @@
1919
"exact": lambda column, value: column == value,
2020
"gt": lambda column, value: column > value,
2121
"gte": lambda column, value: column >= value,
22-
"icontains": lambda column, value: sa.func.lower(column).contains(
23-
lower(value)
24-
),
25-
"iendswith": lambda column, value: sa.func.lower(column).endswith(
26-
lower(value)
27-
),
22+
"icontains": lambda column, value: sa.func.lower(column).contains(lower(value)),
23+
"iendswith": lambda column, value: sa.func.lower(column).endswith(lower(value)),
2824
"iexact": lambda column, value: sa.func.lower(column) == lower(value),
29-
"iin": lambda column, value: sa.func.lower(column).in_(
30-
lower(i) for i in value
31-
),
25+
"iin": lambda column, value: sa.func.lower(column).in_(lower(i) for i in value),
3226
"in": lambda column, value: column.in_(value),
33-
"isnull": lambda column, value: column is None
34-
if value
35-
else column != None,
36-
"istartswith": lambda column, value: sa.func.lower(column).startswith(
37-
lower(value)
38-
),
27+
"isnull": lambda column, value: column is None if value else column != None,
28+
"istartswith": lambda column, value: sa.func.lower(column).startswith(lower(value)),
3929
"lt": lambda column, value: column < value,
4030
"lte": lambda column, value: column <= value,
4131
"range": lambda column, value: column.between(*value),
@@ -233,7 +223,6 @@ def __get__(self, instance, owner):
233223
f"Cannot access {self.__class__.__name__} when not bound to a model. You can explicitly instantiate descriptor with model class - `db.queryproperty(Model)`."
234224
)
235225

236-
237226
try:
238227
mapper = sa.orm.class_mapper(model)
239228
except sa.orm.exc.UnmappedClassError:

django_sorcery/forms.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ def __new__(mcs, name, bases, attrs):
195195
(
196196
base.Meta.formfield_callback
197197
for base in bases
198-
if hasattr(base, "Meta")
199-
and hasattr(base.Meta, "formfield_callback")
198+
if hasattr(base, "Meta") and hasattr(base.Meta, "formfield_callback")
200199
),
201200
None,
202201
)
@@ -338,7 +337,6 @@ def save(self, flush=True, **kwargs):
338337
f"The {self.instance.__class__.__name__} could not be saved because the data didn't validate."
339338
)
340339

341-
342340
if self.instance not in opts.session:
343341
opts.session.add(self.instance)
344342

django_sorcery/formsets/base.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ def __init__(self, data=None, files=None, auto_id="id_%s", prefix=None, queryset
3030

3131
def initial_form_count(self):
3232
"""Return the number of forms that are required in this FormSet."""
33-
return (
34-
super().initial_form_count()
35-
if (self.data or self.files)
36-
else len(self.get_queryset())
37-
)
33+
return super().initial_form_count() if (self.data or self.files) else len(self.get_queryset())
3834

3935
def _existing_object(self, pk):
4036
info = meta.model_info(self.model)

django_sorcery/formsets/inline.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def _get_foreign_key(relation, parent_model, model, fk_name=None):
4949
if len(relations) == 1:
5050
return relations[0]
5151

52-
raise ValueError(
53-
f"Couldn't find a relation from '{parent_model.__name__}' to '{model.__name__}'."
54-
)
52+
raise ValueError(f"Couldn't find a relation from '{parent_model.__name__}' to '{model.__name__}'.")
5553

5654

5755
def inlineformset_factory(

django_sorcery/management/alembic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def get_app_config(self, app, db):
6565
or f'alembic_version_{app.label.lower().replace(".", "_")}'
6666
)
6767

68-
6968
max_length = db.engine.dialect.max_identifier_length
7069
if max_length and len(version_table) >= max_length:
7170
raise CommandError(

django_sorcery/validators/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ def __call__(self, m):
7272
if state.persistent:
7373
# need to exlude the current model since it's already in db
7474
pks = info.mapper.primary_key_from_instance(m)
75-
clauses.extend(
76-
getattr(m.__class__, name) != pk
77-
for name, pk in zip(info.primary_keys, pks)
78-
)
75+
clauses.extend(getattr(m.__class__, name) != pk for name, pk in zip(info.primary_keys, pks))
7976

8077
query = self.session.query(m.__class__).filter(*clauses)
8178
exists = self.session.query(sa.literal(True)).filter(query.exists()).scalar()

test_site/polls/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ def get_form_context_data(self, **kwargs):
2828
def get_choice_formset(self, instance=None):
2929
if not hasattr(self, "_choice_formset"):
3030
instance = instance or self.object
31-
self._choice_formset = ChoiceFormSet(
32-
instance=instance, data=self.request.POST or None
33-
)
34-
31+
self._choice_formset = ChoiceFormSet(instance=instance, data=self.request.POST or None)
3532

3633
return self._choice_formset
3734

0 commit comments

Comments
 (0)