Skip to content

Commit 1a5f26d

Browse files
authored
Merge pull request #557 from jazzband/add-pre-commit
Add pre commit
2 parents 564284e + b1a26e8 commit 1a5f26d

File tree

10 files changed

+35
-31
lines changed

10 files changed

+35
-31
lines changed

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/psf/black-pre-commit-mirror
9+
rev: 23.11.0
10+
hooks:
11+
- id: black
12+
exclude: '.*migrations.*'

docs/advanced.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ If you insert ``.non_polymorphic()`` anywhere into the query chain, then
136136
django_polymorphic will simply leave out the final step of retrieving the
137137
real objects, and the manager/queryset will return objects of the type of
138138
the base class you used for the query, like vanilla Django would
139-
(``ModelA`` in this example).
139+
(``ModelA`` in this example).
140140

141141
>>> qs=ModelA.objects.non_polymorphic().all()
142142
>>> qs
@@ -188,7 +188,7 @@ About Queryset Methods
188188
* ``values()`` & ``values_list()`` currently do not return polymorphic
189189
results. This may change in the future however. If you want to use these
190190
methods now, it's best if you use ``Model.base_objects.values...`` as
191-
this is guaranteed to not change.
191+
this is guaranteed to not change.
192192

193193
* ``defer()`` and ``only()`` work as expected. On Django 1.5+ they support
194194
the ``ModelX___field`` syntax, but on Django 1.4 it is only possible to
@@ -252,7 +252,7 @@ Restrictions & Caveats
252252
the resulting objects are required to have a unique primary key within
253253
the result set.
254254

255-
* Diamond shaped inheritance: There seems to be a general problem
255+
* Diamond shaped inheritance: There seems to be a general problem
256256
with diamond shaped multiple model inheritance with Django models
257257
(tested with V1.1 - V1.3).
258258
An example is here: http://code.djangoproject.com/ticket/10808.
@@ -288,4 +288,3 @@ Restrictions & Caveats
288288
- http://groups.google.com/group/django-users/browse_thread/thread/52f72cffebb705e/bc18c18b2e83881e?lnk=gst&q=model+inheritance#bc18c18b2e83881e
289289
- http://code.djangoproject.com/ticket/10808
290290
- http://code.djangoproject.com/ticket/7270
291-

docs/api/polymorphic.admin.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,3 @@ These classes are useful when existing parts of the admin classes.
9090

9191
.. autoclass:: polymorphic.admin.PolymorphicInlineAdminFormSet
9292
:show-inheritance:
93-

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ Indices and tables
8181
* :ref:`genindex`
8282
* :ref:`modindex`
8383
* :ref:`search`
84-

example/pexp/dumpdata_test_correct_output.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
[
22
{
3-
"pk": 1,
4-
"model": "pexp.project",
3+
"pk": 1,
4+
"model": "pexp.project",
55
"fields": {
6-
"topic": "John's gathering",
6+
"topic": "John's gathering",
77
"polymorphic_ctype": 2
88
}
9-
},
9+
},
1010
{
11-
"pk": 2,
12-
"model": "pexp.project",
11+
"pk": 2,
12+
"model": "pexp.project",
1313
"fields": {
14-
"topic": "Sculpting with Tim",
14+
"topic": "Sculpting with Tim",
1515
"polymorphic_ctype": 3
1616
}
17-
},
17+
},
1818
{
19-
"pk": 3,
20-
"model": "pexp.project",
19+
"pk": 3,
20+
"model": "pexp.project",
2121
"fields": {
22-
"topic": "Swallow Aerodynamics",
22+
"topic": "Swallow Aerodynamics",
2323
"polymorphic_ctype": 4
2424
}
25-
},
25+
},
2626
{
27-
"pk": 2,
28-
"model": "pexp.artproject",
27+
"pk": 2,
28+
"model": "pexp.artproject",
2929
"fields": {
3030
"artist": "T. Turner"
3131
}
32-
},
32+
},
3333
{
34-
"pk": 3,
35-
"model": "pexp.researchproject",
34+
"pk": 3,
35+
"model": "pexp.researchproject",
3636
"fields": {
3737
"supervisor": "Dr. Winter"
3838
}

polymorphic/formsets/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def __init__(
4141
help_texts=None,
4242
error_messages=None,
4343
):
44-
4544
self.model = model
4645

4746
# Instead of initializing the form here right away,

polymorphic/query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def _polymorphic_iterator(self, base_iter):
5353
# Make sure the base iterator is read in chunks instead of
5454
# reading it completely, in case our caller read only a few objects.
5555
for i in range(Polymorphic_QuerySet_objects_per_request):
56-
5756
try:
5857
o = next(base_iter)
5958
base_result_objects.append(o)
@@ -258,7 +257,8 @@ def _polymorphic_add_immediate_loading(self, field_names):
258257

259258
def _process_aggregate_args(self, args, kwargs):
260259
"""for aggregate and annotate kwargs: allow ModelX___field syntax for kwargs, forbid it for args.
261-
Modifies kwargs if needed (these are Aggregate objects, we translate the lookup member variable)"""
260+
Modifies kwargs if needed (these are Aggregate objects, we translate the lookup member variable)
261+
"""
262262
___lookup_assert_msg = "PolymorphicModel: annotate()/aggregate(): ___ model lookup supported for keyword arguments only"
263263

264264
def patch_lookup(a):
@@ -386,7 +386,6 @@ class self.model, but as a class derived from self.model. We want to re-fetch
386386
).pk
387387

388388
for i, base_object in enumerate(base_result_objects):
389-
390389
if base_object.polymorphic_ctype_id == self_model_class_id:
391390
# Real class is exactly the same as base class, go straight to results
392391
resultlist.append(base_object)

polymorphic/query_translate.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def translate_polymorphic_filter_definitions_in_kwargs(
4040
"""
4141
additional_args = []
4242
for field_path, val in kwargs.copy().items(): # Python 3 needs copy
43-
4443
new_expr = _translate_polymorphic_filter_definition(
4544
queryset_model, field_path, val, using=using
4645
)

polymorphic/tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ class ProxyModelB(ProxyModelBase):
372372
# class TestBadFieldModel(ShowFieldType, PolymorphicModel):
373373
# instance_of = models.CharField(max_length=10)
374374

375+
375376
# validation error: "polymorphic.relatednameclash: Accessor for field 'polymorphic_ctype' clashes
376377
# with related field 'ContentType.relatednameclash_set'." (reported by Andrew Ingram)
377378
# fixed with related_name
@@ -401,7 +402,6 @@ class CustomPkInherit(CustomPkBase):
401402

402403

403404
class DateModel(PolymorphicModel):
404-
405405
date = models.DateTimeField()
406406

407407

polymorphic/tests/test_orm.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,6 @@ def test_polymorphic__filtered_relation(self):
10771077
self.assertIsInstance(result.last(), BlogB)
10781078

10791079
def test_polymorphic__expressions(self):
1080-
10811080
from django.db.models.functions import Concat
10821081

10831082
# no exception raised
@@ -1240,6 +1239,5 @@ def test_refresh_from_db_fields(self):
12401239
assert obj.field1 == "aa1"
12411240

12421241
def test_non_polymorphic_parent(self):
1243-
12441242
obj = NonPolymorphicParent.objects.create()
12451243
assert obj.delete()

0 commit comments

Comments
 (0)