Skip to content

Commit 4039e60

Browse files
hramezanijeking3
authored andcommitted
Update syntax to Python3.7+
1 parent 5816334 commit 4039e60

File tree

18 files changed

+60
-76
lines changed

18 files changed

+60
-76
lines changed

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# django-simple-history documentation build configuration file, created by
43
# sphinx-quickstart on Sun May 5 16:10:02 2013.

simple_history/admin.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SimpleHistoryAdmin(admin.ModelAdmin):
2525

2626
def get_urls(self):
2727
"""Returns the additional urls used by the Reversion admin."""
28-
urls = super(SimpleHistoryAdmin, self).get_urls()
28+
urls = super().get_urls()
2929
admin_site = self.admin_site
3030
opts = self.model._meta
3131
info = opts.app_label, opts.model_name
@@ -74,7 +74,7 @@ def history_view(self, request, object_id, extra_context=None):
7474
content_type = self.content_type_model_cls.objects.get_by_natural_key(
7575
*USER_NATURAL_KEY
7676
)
77-
admin_user_view = "admin:%s_%s_change" % (
77+
admin_user_view = "admin:{}_{}_change".format(
7878
content_type.app_label,
7979
content_type.model,
8080
)
@@ -113,12 +113,12 @@ def response_change(self, request, obj):
113113
}
114114

115115
self.message_user(
116-
request, "%s - %s" % (msg, _("You may edit it again below"))
116+
request, "{} - {}".format(msg, _("You may edit it again below"))
117117
)
118118

119119
return http.HttpResponseRedirect(request.path)
120120
else:
121-
return super(SimpleHistoryAdmin, self).response_change(request, obj)
121+
return super().response_change(request, obj)
122122

123123
def history_form_view(self, request, object_id, version_id, extra_context=None):
124124
request.current_app = self.admin_site.name
@@ -224,7 +224,7 @@ def render_history_view(self, request, template, context, **kwargs):
224224
def save_model(self, request, obj, form, change):
225225
"""Set special model attribute to user for reference after save"""
226226
obj._history_user = request.user
227-
super(SimpleHistoryAdmin, self).save_model(request, obj, form, change)
227+
super().save_model(request, obj, form, change)
228228

229229
@property
230230
def content_type_model_cls(self):

simple_history/management/commands/clean_duplicate_history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _process(self, to_process, date_back=None, dry_run=True):
6767
if stop_date:
6868
m_qs = m_qs.filter(history_date__gte=stop_date)
6969
found = m_qs.count()
70-
self.log("{0} has {1} historical entries".format(model, found), 2)
70+
self.log(f"{model} has {found} historical entries", 2)
7171
if not found:
7272
continue
7373

simple_history/management/commands/clean_old_history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _process(self, to_process, days_back=None, dry_run=True):
6161
history_date__lt=start_date
6262
)
6363
found = history_model_manager.count()
64-
self.log("{0} has {1} old historical entries".format(model, found), 2)
64+
self.log(f"{model} has {found} old historical entries", 2)
6565
if not found:
6666
continue
6767
if not dry_run:

simple_history/management/commands/populate_history.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Command(BaseCommand):
2424
INVALID_MODEL_ARG = "An invalid model was specified"
2525

2626
def add_arguments(self, parser):
27-
super(Command, self).add_arguments(parser)
27+
super().add_arguments(parser)
2828
parser.add_argument("models", nargs="*", type=str)
2929
parser.add_argument(
3030
"--auto",
@@ -82,7 +82,7 @@ def _handle_model_list(self, *args):
8282
model, history = self._model_from_natural_key(natural_key)
8383
except ValueError as e:
8484
failing = True
85-
self.stderr.write("{error}\n".format(error=e))
85+
self.stderr.write(f"{e}\n")
8686
else:
8787
if not failing:
8888
yield (model, history)
@@ -100,12 +100,12 @@ def _model_from_natural_key(self, natural_key):
100100
except LookupError:
101101
model = None
102102
if not model:
103-
msg = self.MODEL_NOT_FOUND + " < {model} >\n".format(model=natural_key)
103+
msg = self.MODEL_NOT_FOUND + f" < {natural_key} >\n"
104104
raise ValueError(msg)
105105
try:
106106
history_model = utils.get_history_model_for_model(model)
107107
except NotHistoricalModelError:
108-
msg = self.MODEL_NOT_HISTORICAL + " < {model} >\n".format(model=natural_key)
108+
msg = self.MODEL_NOT_HISTORICAL + f" < {natural_key} >\n"
109109
raise ValueError(msg)
110110
return model, history_model
111111

simple_history/manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HistoricalQuerySet(QuerySet):
2020
"""
2121

2222
def __init__(self, *args, **kwargs):
23-
super(HistoricalQuerySet, self).__init__(*args, **kwargs)
23+
super().__init__(*args, **kwargs)
2424
self._as_instances = False
2525
self._pk_attr = self.model.instance_type._meta.pk.attname
2626

@@ -120,12 +120,12 @@ def __get__(self, instance, owner):
120120

121121
class HistoryManager(models.Manager):
122122
def __init__(self, model, instance=None):
123-
super(HistoryManager, self).__init__()
123+
super().__init__()
124124
self.model = model
125125
self.instance = instance
126126

127127
def get_super_queryset(self):
128-
return super(HistoryManager, self).get_queryset()
128+
return super().get_queryset()
129129

130130
def get_queryset(self):
131131
qs = self.get_super_queryset()

simple_history/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def finalize(self, sender, **kwargs):
177177

178178
def get_history_model_name(self, model):
179179
if not self.custom_model_name:
180-
return "Historical{}".format(model._meta.object_name)
180+
return f"Historical{model._meta.object_name}"
181181
# Must be trying to use a custom history model name
182182
if callable(self.custom_model_name):
183183
name = self.custom_model_name(model._meta.object_name)
@@ -224,7 +224,7 @@ def create_history_model(self, model, inherited):
224224
attrs.update(fields)
225225
attrs.update(self.get_extra_fields(model, fields))
226226
# type in python2 wants str as a first argument
227-
attrs.update(Meta=type(str("Meta"), (), self.get_meta_options(model)))
227+
attrs.update(Meta=type("Meta", (), self.get_meta_options(model)))
228228
if self.table_name is not None:
229229
attrs["Meta"].db_table = self.table_name
230230

@@ -386,7 +386,7 @@ def revert_url(self):
386386
opts = model._meta
387387
app_label, model_name = opts.app_label, opts.model_name
388388
return reverse(
389-
"%s:%s_%s_simple_history" % (admin.site.name, app_label, model_name),
389+
f"{admin.site.name}:{app_label}_{model_name}_simple_history",
390390
args=[getattr(self, opts.pk.attname), self.history_id],
391391
)
392392

simple_history/registry_tests/migration_test_app/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.9.12 on 2017-01-18 21:58
32
import django.db.models.deletion
43
from django.conf import settings

simple_history/registry_tests/migration_test_app/models.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ class Yar(models.Model):
1919
class CustomAttrNameForeignKey(models.ForeignKey):
2020
def __init__(self, *args, **kwargs):
2121
self.attr_name = kwargs.pop("attr_name", None)
22-
super(CustomAttrNameForeignKey, self).__init__(*args, **kwargs)
22+
super().__init__(*args, **kwargs)
2323

2424
def get_attname(self):
25-
return self.attr_name or super(CustomAttrNameForeignKey, self).get_attname()
25+
return self.attr_name or super().get_attname()
2626

2727
def deconstruct(self):
28-
name, path, args, kwargs = super(CustomAttrNameForeignKey, self).deconstruct()
28+
name, path, args, kwargs = super().deconstruct()
2929
if self.attr_name:
3030
kwargs["attr_name"] = self.attr_name
3131
return name, path, args, kwargs
@@ -41,15 +41,13 @@ class ModelWithCustomAttrForeignKey(models.Model):
4141
class CustomAttrNameOneToOneField(models.OneToOneField):
4242
def __init__(self, *args, **kwargs):
4343
self.attr_name = kwargs.pop("attr_name", None)
44-
super(CustomAttrNameOneToOneField, self).__init__(*args, **kwargs)
44+
super().__init__(*args, **kwargs)
4545

4646
def get_attname(self):
47-
return self.attr_name or super(CustomAttrNameOneToOneField, self).get_attname()
47+
return self.attr_name or super().get_attname()
4848

4949
def deconstruct(self):
50-
name, path, args, kwargs = super(
51-
CustomAttrNameOneToOneField, self
52-
).deconstruct()
50+
name, path, args, kwargs = super().deconstruct()
5351
if self.attr_name:
5452
kwargs["attr_name"] = self.attr_name
5553
return name, path, args, kwargs
@@ -59,6 +57,4 @@ class ModelWithCustomAttrOneToOneField(models.Model):
5957
what_i_mean = CustomAttrNameOneToOneField(
6058
WhatIMean, models.CASCADE, attr_name="custom_attr_name"
6159
)
62-
history = HistoricalRecords(
63-
excluded_field_kwargs={"what_i_mean": set(["attr_name"])}
64-
)
60+
history = HistoricalRecords(excluded_field_kwargs={"what_i_mean": {"attr_name"}})

simple_history/registry_tests/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class TestTrackingInheritance(TestCase):
105105
def test_tracked_abstract_base(self):
106106
self.assertEqual(
107107
sorted(
108-
[f.attname for f in TrackedWithAbstractBase.history.model._meta.fields]
108+
f.attname for f in TrackedWithAbstractBase.history.model._meta.fields
109109
),
110110
sorted(
111111
[

0 commit comments

Comments
 (0)