Skip to content

Commit 8a5b555

Browse files
committed
Used pyupgrade to remove Python 2 and 3.5 compatibility code
1 parent 6c69ea2 commit 8a5b555

31 files changed

+114
-138
lines changed

docs/conf.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# django-polymorphic documentation build configuration file, created by
43
# sphinx-quickstart on Sun May 19 12:20:47 2013.
@@ -53,8 +52,8 @@
5352
master_doc = "index"
5453

5554
# General information about the project.
56-
project = u"django-polymorphic"
57-
copyright = u"2013, Bert Constantin, Chris Glass, Diederik van der Boor"
55+
project = "django-polymorphic"
56+
copyright = "2013, Bert Constantin, Chris Glass, Diederik van der Boor"
5857

5958
# The version info for the project you're documenting, acts as replacement for
6059
# |version| and |release|, also used in various other places throughout the
@@ -198,8 +197,8 @@
198197
(
199198
"index",
200199
"django-polymorphic.tex",
201-
u"django-polymorphic Documentation",
202-
u"Bert Constantin, Chris Glass, Diederik van der Boor",
200+
"django-polymorphic Documentation",
201+
"Bert Constantin, Chris Glass, Diederik van der Boor",
203202
"manual",
204203
)
205204
]
@@ -233,8 +232,8 @@
233232
(
234233
"index",
235234
"django-polymorphic",
236-
u"django-polymorphic Documentation",
237-
[u"Bert Constantin, Chris Glass, Diederik van der Boor"],
235+
"django-polymorphic Documentation",
236+
["Bert Constantin, Chris Glass, Diederik van der Boor"],
238237
1,
239238
)
240239
]
@@ -252,8 +251,8 @@
252251
(
253252
"index",
254253
"django-polymorphic",
255-
u"django-polymorphic Documentation",
256-
u"Bert Constantin, Chris Glass, Diederik van der Boor",
254+
"django-polymorphic Documentation",
255+
"Bert Constantin, Chris Glass, Diederik van der Boor",
257256
"django-polymorphic",
258257
"One line description of project.",
259258
"Miscellaneous",

example/orders/migrations/0001_initial.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
41
from django.db import migrations, models
52

63

example/orders/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Meta:
3535
verbose_name_plural = _("Payments")
3636

3737
def __str__(self):
38-
return "{0} {1}".format(self.currency, self.amount)
38+
return f"{self.currency} {self.amount}"
3939

4040

4141
class CreditCardPayment(Payment):

example/pexp/management/commands/p2cmd.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
This module is a scratchpad for general development, testing & debugging
43
Well, even more so than pcmd.py. You best ignore p2cmd.py.

example/pexp/management/commands/polybench.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
This module is a scratchpad for general development, testing & debugging
43
"""

example/pexp/management/commands/polymorphic_create_test_data.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
This module is a scratchpad for general development, testing & debugging
43
"""

example/pexp/migrations/0001_initial.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
41
from django.db import migrations, models
52

63
import polymorphic.showfields

example/pexp/models.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from django.db import models
42

53
from polymorphic.models import PolymorphicModel
@@ -41,7 +39,7 @@ class ProxyBase(PolymorphicModel):
4139
title = models.CharField(max_length=200)
4240

4341
def __unicode__(self):
44-
return u"<ProxyBase[type={0}]: {1}>".format(self.polymorphic_ctype, self.title)
42+
return f"<ProxyBase[type={self.polymorphic_ctype}]: {self.title}>"
4543

4644
class Meta:
4745
ordering = ("title",)
@@ -52,15 +50,15 @@ class Meta:
5250
proxy = True
5351

5452
def __unicode__(self):
55-
return u"<ProxyA: {0}>".format(self.title)
53+
return f"<ProxyA: {self.title}>"
5654

5755

5856
class ProxyB(ProxyBase):
5957
class Meta:
6058
proxy = True
6159

6260
def __unicode__(self):
63-
return u"<ProxyB: {0}>".format(self.title)
61+
return f"<ProxyB: {self.title}>"
6462

6563

6664
# Internals for management command tests

polymorphic/__init__.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
Seamless Polymorphic Inheritance for Django Models
43

polymorphic/admin/childadmin.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class PolymorphicChildModelAdmin(admin.ModelAdmin):
4747
show_in_index = False
4848

4949
def __init__(self, model, admin_site, *args, **kwargs):
50-
super(PolymorphicChildModelAdmin, self).__init__(
50+
super().__init__(
5151
model, admin_site, *args, **kwargs
5252
)
5353

@@ -68,7 +68,7 @@ def get_form(self, request, obj=None, **kwargs):
6868
if not self.fieldsets and not self.fields:
6969
kwargs.setdefault("fields", "__all__")
7070

71-
return super(PolymorphicChildModelAdmin, self).get_form(request, obj, **kwargs)
71+
return super().get_form(request, obj, **kwargs)
7272

7373
def get_model_perms(self, request):
7474
match = resolve(request.path_info)
@@ -79,7 +79,7 @@ def get_model_perms(self, request):
7979
and match.url_name in ("index", "app_list")
8080
):
8181
return {"add": False, "change": False, "delete": False}
82-
return super(PolymorphicChildModelAdmin, self).get_model_perms(request)
82+
return super().get_model_perms(request)
8383

8484
@property
8585
def change_form_template(self):
@@ -91,7 +91,7 @@ def change_form_template(self):
9191
base_app_label = base_opts.app_label
9292

9393
return [
94-
"admin/%s/%s/change_form.html" % (app_label, opts.object_name.lower()),
94+
f"admin/{app_label}/{opts.object_name.lower()}/change_form.html",
9595
"admin/%s/change_form.html" % app_label,
9696
# Added:
9797
"admin/%s/%s/change_form.html"
@@ -132,7 +132,7 @@ def object_history_template(self):
132132
base_app_label = base_opts.app_label
133133

134134
return [
135-
"admin/%s/%s/object_history.html" % (app_label, opts.object_name.lower()),
135+
f"admin/{app_label}/{opts.object_name.lower()}/object_history.html",
136136
"admin/%s/object_history.html" % app_label,
137137
# Added:
138138
"admin/%s/%s/object_history.html"
@@ -147,7 +147,7 @@ def _get_parent_admin(self):
147147
parent_model = self.model._meta.get_field("polymorphic_ctype").model
148148
if parent_model == self.model:
149149
# when parent_model is in among child_models, just return super instance
150-
return super(PolymorphicChildModelAdmin, self)
150+
return super()
151151

152152
try:
153153
return self.admin_site._registry[parent_model]
@@ -167,7 +167,7 @@ def _get_parent_admin(self):
167167

168168
# If we get this far without returning there is no admin available
169169
raise ParentAdminNotRegistered(
170-
"No parent admin was registered for a '{0}' model.".format(parent_model)
170+
f"No parent admin was registered for a '{parent_model}' model."
171171
)
172172

173173
def response_post_save_add(self, request, obj):
@@ -180,13 +180,13 @@ def render_change_form(
180180
self, request, context, add=False, change=False, form_url="", obj=None
181181
):
182182
context.update({"base_opts": self.base_model._meta})
183-
return super(PolymorphicChildModelAdmin, self).render_change_form(
183+
return super().render_change_form(
184184
request, context, add=add, change=change, form_url=form_url, obj=obj
185185
)
186186

187187
def delete_view(self, request, object_id, context=None):
188188
extra_context = {"base_opts": self.base_model._meta}
189-
return super(PolymorphicChildModelAdmin, self).delete_view(
189+
return super().delete_view(
190190
request, object_id, extra_context
191191
)
192192

@@ -195,7 +195,7 @@ def history_view(self, request, object_id, extra_context=None):
195195
context = {"base_opts": self.base_model._meta}
196196
if extra_context:
197197
context.update(extra_context)
198-
return super(PolymorphicChildModelAdmin, self).history_view(
198+
return super().history_view(
199199
request, object_id, extra_context=context
200200
)
201201

@@ -209,7 +209,7 @@ def get_fieldsets(self, request, obj=None):
209209

210210
# If subclass declares fieldsets or fields, this is respected
211211
if self.fieldsets or self.fields or not self.base_fieldsets:
212-
return super(PolymorphicChildModelAdmin, self).get_fieldsets(request, obj)
212+
return super().get_fieldsets(request, obj)
213213

214214
# Have a reasonable default fieldsets,
215215
# where the subclass fields are automatically included.

0 commit comments

Comments
 (0)