Skip to content

Commit db864cd

Browse files
committed
Corrected black code wrapping when lines had long comments.
1 parent 6af023d commit db864cd

9 files changed

Lines changed: 50 additions & 66 deletions

File tree

polymorphic/admin/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ class PolymorphicInlineAdminFormSet(InlineAdminFormSet):
3232
"""
3333

3434
def __init__(self, *args, **kwargs):
35-
self.request = kwargs.pop(
36-
"request", None
37-
) # Assigned later via PolymorphicInlineSupportMixin later.
35+
# Assigned later via PolymorphicInlineSupportMixin later.
36+
self.request = kwargs.pop("request", None)
3837
self.obj = kwargs.pop("obj", None)
3938
super(PolymorphicInlineAdminFormSet, self).__init__(*args, **kwargs)
4039

polymorphic/admin/inlines.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ def get_formset_child(self, request, obj=None, **kwargs):
229229
exclude = list(self.exclude)
230230

231231
exclude.extend(self.get_readonly_fields(request, obj))
232-
exclude.append(
233-
"polymorphic_ctype"
234-
) # Django 1.10 blocks it, as it's a readonly field.
232+
# Add forcefully, as Django 1.10 doesn't include readonly fields.
233+
exclude.append("polymorphic_ctype")
235234

236235
if (
237236
self.exclude is None

polymorphic/admin/parentadmin.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ def _get_real_admin_by_ct(self, ct_id, super_if_self=True):
177177

178178
model_class = ct.model_class()
179179
if not model_class:
180-
raise Http404(
181-
"No model found for '{0}.{1}'.".format(*ct.natural_key())
182-
) # Handle model deletion
180+
# Handle model deletion
181+
raise Http404("No model found for '{0}.{1}'.".format(*ct.natural_key()))
183182

184183
return self._get_real_admin_by_model(model_class, super_if_self=super_if_self)
185184

polymorphic/managers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ def from_queryset(cls, queryset_class, class_name=None):
2828
manager = super(PolymorphicManager, cls).from_queryset(
2929
queryset_class, class_name=class_name
3030
)
31-
manager.queryset_class = (
32-
queryset_class
33-
) # also set our version, Django uses _queryset_class
31+
# also set our version, Django uses _queryset_class
32+
manager.queryset_class = queryset_class
3433
return manager
3534

3635
def get_queryset(self):

polymorphic/models.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,23 @@ def add_model_if_regular(model, field_name, result):
245245

246246
def add_all_super_models(model, result):
247247
for super_cls, field_to_super in model._meta.parents.items():
248-
if field_to_super is not None: # if not a link to a proxy model
249-
field_name = (
250-
field_to_super.name
251-
) # the field on model can have a different name to super_cls._meta.module_name, if the field is created manually using 'parent_link'
248+
if field_to_super is not None:
249+
# if not a link to a proxy model, the field on model can have
250+
# a different name to super_cls._meta.module_name, when the field
251+
# is created manually using 'parent_link'
252+
field_name = field_to_super.name
252253
add_model_if_regular(super_cls, field_name, result)
253254
add_all_super_models(super_cls, result)
254255

255256
def add_all_sub_models(super_cls, result):
256-
for (
257-
sub_cls
258-
) in super_cls.__subclasses__(): # go through all subclasses of model
259-
if (
260-
super_cls in sub_cls._meta.parents
261-
): # super_cls may not be in sub_cls._meta.parents if super_cls is a proxy model
262-
field_to_super = sub_cls._meta.parents[
263-
super_cls
264-
] # get the field that links sub_cls to super_cls
265-
if (
266-
field_to_super is not None
267-
): # if filed_to_super is not a link to a proxy model
257+
# go through all subclasses of model
258+
for sub_cls in super_cls.__subclasses__():
259+
# super_cls may not be in sub_cls._meta.parents if super_cls is a proxy model
260+
if super_cls in sub_cls._meta.parents:
261+
# get the field that links sub_cls to super_cls
262+
field_to_super = sub_cls._meta.parents[super_cls]
263+
# if filed_to_super is not a link to a proxy model
264+
if field_to_super is not None:
268265
super_to_sub_related_field = field_to_super.remote_field
269266
if super_to_sub_related_field.related_name is None:
270267
# if related name is None the related field is the name of the subclass

polymorphic/query.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@ def _filter_or_exclude(self, negate, *args, **kwargs):
164164
# We override this internal Django functon as it is used for all filter member functions.
165165
q_objects = translate_polymorphic_filter_definitions_in_args(
166166
self.model, args, using=self.db
167-
) # the Q objects
167+
)
168+
# filter_field='data'
168169
additional_args = translate_polymorphic_filter_definitions_in_kwargs(
169170
self.model, kwargs, using=self.db
170-
) # filter_field='data'
171+
)
171172
return super(PolymorphicQuerySet, self)._filter_or_exclude(
172173
negate, *(list(q_objects) + additional_args), **kwargs
173174
)
@@ -408,9 +409,8 @@ class self.model, but as a class derived from self.model. We want to re-fetch
408409
real_objects = real_concrete_class._base_objects.db_manager(self.db).filter(
409410
**{("%s__in" % pk_name): idlist}
410411
)
411-
real_objects.query.select_related = (
412-
self.query.select_related
413-
) # copy select related configuration to new qs
412+
# copy select related configuration to new qs
413+
real_objects.query.select_related = self.query.select_related
414414

415415
# Copy deferred fields configuration to the new queryset
416416
deferred_loading_fields = []
@@ -479,17 +479,15 @@ class self.model, but as a class derived from self.model. We want to re-fetch
479479

480480
# set polymorphic_annotate_names in all objects (currently just used for debugging/printing)
481481
if self.query.annotations:
482-
annotate_names = list(
483-
self.query.annotations.keys()
484-
) # get annotate field list
482+
# get annotate field list
483+
annotate_names = list(self.query.annotations.keys())
485484
for real_object in resultlist:
486485
real_object.polymorphic_annotate_names = annotate_names
487486

488487
# set polymorphic_extra_select_names in all objects (currently just used for debugging/printing)
489488
if self.query.extra_select:
490-
extra_select_names = list(
491-
self.query.extra_select.keys()
492-
) # get extra select field list
489+
# get extra select field list
490+
extra_select_names = list(self.query.extra_select.keys())
493491
for real_object in resultlist:
494492
real_object.polymorphic_extra_select_names = extra_select_names
495493

polymorphic/showfields.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
class ShowFieldBase(object):
1414
""" base class for the ShowField... model mixins, does the work """
1515

16-
polymorphic_query_multiline_output = (
17-
True
18-
) # cause nicer multiline PolymorphicQuery output
16+
# cause nicer multiline PolymorphicQuery output
17+
polymorphic_query_multiline_output = True
1918

2019
polymorphic_showfield_type = False
2120
polymorphic_showfield_content = False

polymorphic/tests/models.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ class ModelUnderRelChild(PolymorphicModel):
157157

158158
class MyManagerQuerySet(PolymorphicQuerySet):
159159
def my_queryset_foo(self):
160-
return (
161-
self.all()
162-
) # Just a method to prove the existance of the custom queryset.
160+
# Just a method to prove the existence of the custom queryset.
161+
return self.all()
163162

164163

165164
class MyManager(PolymorphicManager):
@@ -205,9 +204,8 @@ class MROBase2(MROBase1):
205204

206205

207206
class MROBase3(models.Model):
208-
base_3_id = models.AutoField(
209-
primary_key=True
210-
) # make sure 'id' field doesn't clash, detected by Django 1.11
207+
# make sure 'id' field doesn't clash, detected by Django 1.11
208+
base_3_id = models.AutoField(primary_key=True)
211209
objects = models.Manager()
212210

213211

@@ -232,9 +230,8 @@ class ChildModelWithManager(PolymorphicModel):
232230

233231
class PlainMyManagerQuerySet(QuerySet):
234232
def my_queryset_foo(self):
235-
return (
236-
self.all()
237-
) # Just a method to prove the existence of the custom queryset.
233+
# Just a method to prove the existence of the custom queryset.
234+
return self.all()
238235

239236

240237
class PlainMyManager(models.Manager):

polymorphic/tests/test_orm.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,8 @@ def test_user_defined_manager(self):
812812
ModelWithMyManager.objects.create(field1="D1a", field4="D4a")
813813
ModelWithMyManager.objects.create(field1="D1b", field4="D4b")
814814

815-
objects = (
816-
ModelWithMyManager.objects.all()
817-
) # MyManager should reverse the sorting of field1
815+
# MyManager should reverse the sorting of field1
816+
objects = ModelWithMyManager.objects.all()
818817
self.assertQuerysetEqual(
819818
objects,
820819
[(ModelWithMyManager, "D1b", "D4b"), (ModelWithMyManager, "D1a", "D4a")],
@@ -830,9 +829,8 @@ def test_user_defined_manager_as_secondary(self):
830829
ModelWithMyManagerNoDefault.objects.create(field1="D1a", field4="D4a")
831830
ModelWithMyManagerNoDefault.objects.create(field1="D1b", field4="D4b")
832831

833-
objects = (
834-
ModelWithMyManagerNoDefault.my_objects.all()
835-
) # MyManager should reverse the sorting of field1
832+
# MyManager should reverse the sorting of field1
833+
objects = ModelWithMyManagerNoDefault.my_objects.all()
836834
self.assertQuerysetEqual(
837835
objects,
838836
[
@@ -1049,9 +1047,8 @@ def test_parent_link_and_related_name(self):
10491047
p = ModelShow1_plain.objects.non_polymorphic().get(
10501048
field1="TestParentLinkAndRelatedName"
10511049
)
1052-
self.assertNotEqual(
1053-
p, t
1054-
) # p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
1050+
# p should be Plain1 and t TestParentLinkAndRelatedName, so not equal
1051+
self.assertNotEqual(p, t)
10551052
self.assertEqual(p, t.superclass)
10561053
self.assertEqual(p.related_name_subclass, t)
10571054

@@ -1228,12 +1225,12 @@ def test_prefetch_related_with_missing(self):
12281225
qs = RelatingModel.objects.order_by("pk").prefetch_related("many2many")
12291226
objects = list(qs)
12301227
self.assertEqual(len(objects[0].many2many.all()), 1)
1231-
self.assertEqual(
1232-
len(objects[1].many2many.all()), 0
1233-
) # derived object was not fetched
1234-
self.assertEqual(
1235-
len(objects[1].many2many.non_polymorphic()), 1
1236-
) # base object does exist
1228+
1229+
# derived object was not fetched
1230+
self.assertEqual(len(objects[1].many2many.all()), 0)
1231+
1232+
# base object does exist
1233+
self.assertEqual(len(objects[1].many2many.non_polymorphic()), 1)
12371234

12381235
def test_refresh_from_db_fields(self):
12391236
"""Test whether refresh_from_db(fields=..) works as it performs .only() queries"""

0 commit comments

Comments
 (0)