Skip to content

Commit 1d639ed

Browse files
authored
Add some Python 3 upgrades (#634)
* Run `pyupgrade` * Remove `object` from class bases
1 parent d230111 commit 1d639ed

36 files changed

+161
-172
lines changed

src/django_mysql/cache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# command
2424

2525

26-
class Options(object):
26+
class Options:
2727
"""A class that will quack like a Django model _meta class.
2828
2929
This allows cache operations to be controlled by the router
@@ -44,10 +44,10 @@ def __init__(self, table):
4444

4545
class BaseDatabaseCache(BaseCache):
4646
def __init__(self, table, params):
47-
super(BaseDatabaseCache, self).__init__(params)
47+
super().__init__(params)
4848
self._table = table
4949

50-
class CacheEntry(object):
50+
class CacheEntry:
5151
_meta = Options(table)
5252

5353
self.cache_model_class = CacheEntry
@@ -109,7 +109,7 @@ def _now(cls):
109109
return int(time() * 1000)
110110

111111
def __init__(self, table, params):
112-
super(MySQLCache, self).__init__(table, params)
112+
super().__init__(table, params)
113113
options = params.get("OPTIONS", {})
114114
self._compress_min_length = options.get("COMPRESS_MIN_LENGTH", 5000)
115115
self._compress_level = options.get("COMPRESS_LEVEL", 6)
@@ -416,7 +416,7 @@ def validate_key(self, key):
416416
raise ValueError(
417417
"Cache key is longer than the maxmimum 250 characters: {}".format(key)
418418
)
419-
return super(MySQLCache, self).validate_key(key)
419+
return super().validate_key(key)
420420

421421
def encode(self, obj):
422422
"""
@@ -469,7 +469,7 @@ def _maybe_cull(self):
469469
def get_backend_timeout(self, timeout=DEFAULT_TIMEOUT):
470470
if timeout is None:
471471
return self.FOREVER_TIMEOUT
472-
timeout = super(MySQLCache, self).get_backend_timeout(timeout)
472+
timeout = super().get_backend_timeout(timeout)
473473
return int(timeout * 1000)
474474

475475
# Our API extensions

src/django_mysql/forms.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SimpleListField(forms.CharField):
2323

2424
def __init__(self, base_field, max_length=None, min_length=None, *args, **kwargs):
2525
self.base_field = base_field
26-
super(SimpleListField, self).__init__(*args, **kwargs)
26+
super().__init__(*args, **kwargs)
2727
if max_length is not None:
2828
self.max_length = max_length
2929
self.validators.append(ListMaxLengthValidator(int(max_length)))
@@ -77,7 +77,7 @@ def to_python(self, value):
7777
return values
7878

7979
def validate(self, value):
80-
super(SimpleListField, self).validate(value)
80+
super().validate(value)
8181
errors = []
8282
for i, item in enumerate(value, start=1):
8383
try:
@@ -100,7 +100,7 @@ def validate(self, value):
100100
raise ValidationError(errors)
101101

102102
def run_validators(self, value):
103-
super(SimpleListField, self).run_validators(value)
103+
super().run_validators(value)
104104
errors = []
105105
for i, item in enumerate(value, start=1):
106106
try:
@@ -137,7 +137,7 @@ class SimpleSetField(forms.CharField):
137137

138138
def __init__(self, base_field, max_length=None, min_length=None, *args, **kwargs):
139139
self.base_field = base_field
140-
super(SimpleSetField, self).__init__(*args, **kwargs)
140+
super().__init__(*args, **kwargs)
141141
if max_length is not None:
142142
self.max_length = max_length
143143
self.validators.append(SetMaxLengthValidator(int(max_length)))
@@ -200,7 +200,7 @@ def to_python(self, value):
200200
return values
201201

202202
def validate(self, value):
203-
super(SimpleSetField, self).validate(value)
203+
super().validate(value)
204204
errors = []
205205
for item in value:
206206
try:
@@ -221,7 +221,7 @@ def validate(self, value):
221221
raise ValidationError(errors)
222222

223223
def run_validators(self, value):
224-
super(SimpleSetField, self).run_validators(value)
224+
super().run_validators(value)
225225
errors = []
226226
for item in value:
227227
try:

src/django_mysql/locks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from django_mysql.exceptions import TimeoutError
88

99

10-
class Lock(object):
10+
class Lock:
1111
def __init__(self, name, acquire_timeout=10.0, using=None):
1212
self.acquire_timeout = acquire_timeout
1313

@@ -83,7 +83,7 @@ def held_with_prefix(cls, prefix, using=DEFAULT_DB_ALIAS):
8383
return {cls.unmake_name(using, row[0]): row[1] for row in cursor.fetchall()}
8484

8585

86-
class TableLock(object):
86+
class TableLock:
8787
def __init__(self, read=None, write=None, using=None):
8888
self.read = self._process_names(read)
8989
self.write = self._process_names(write)

src/django_mysql/models/aggregates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
# This can/will be improved to SetTextField or ListTextField
2828
extra["output_field"] = CharField()
2929

30-
super(GroupConcat, self).__init__(expression, **extra)
30+
super().__init__(expression, **extra)
3131

3232
self.distinct = distinct
3333
self.separator = separator

src/django_mysql/models/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class Model(models.Model):
7-
class Meta(object):
7+
class Meta:
88
abstract = True
99

1010
objects = QuerySet.as_manager()

src/django_mysql/models/expressions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class TwoSidedExpression(BaseExpression):
88
def __init__(self, lhs, rhs):
9-
super(TwoSidedExpression, self).__init__()
9+
super().__init__()
1010
self.lhs = lhs
1111
self.rhs = rhs
1212

@@ -17,7 +17,7 @@ def set_source_expressions(self, exprs):
1717
self.lhs, self.rhs = exprs
1818

1919

20-
class ListF(object):
20+
class ListF:
2121
def __init__(self, field_name):
2222
self.field_name = field_name
2323
self.field = F(field_name)
@@ -122,7 +122,7 @@ class PopListF(BaseExpression):
122122
)
123123

124124
def __init__(self, lhs):
125-
super(PopListF, self).__init__()
125+
super().__init__()
126126
self.lhs = lhs
127127

128128
def get_source_expressions(self):
@@ -151,7 +151,7 @@ class PopLeftListF(BaseExpression):
151151
)
152152

153153
def __init__(self, lhs):
154-
super(PopLeftListF, self).__init__()
154+
super().__init__()
155155
self.lhs = lhs
156156

157157
def get_source_expressions(self):
@@ -167,7 +167,7 @@ def as_sql(self, compiler, connection):
167167
return sql, tuple(field_params)
168168

169169

170-
class SetF(object):
170+
class SetF:
171171
def __init__(self, field_name):
172172
self.field = F(field_name)
173173

src/django_mysql/models/fields/bit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.db.models import BooleanField, NullBooleanField
33

44

5-
class Bit1Mixin(object):
5+
class Bit1Mixin:
66
def db_type(self, connection):
77
return "bit(1)"
88

src/django_mysql/models/fields/dynamic.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def __init__(self, *args, **kwargs):
3535
if "blank" not in kwargs:
3636
kwargs["blank"] = True
3737
self.spec = kwargs.pop("spec", {})
38-
super(DynamicField, self).__init__(*args, **kwargs)
38+
super().__init__(*args, **kwargs)
3939

4040
def check(self, **kwargs):
41-
errors = super(DynamicField, self).check(**kwargs)
41+
errors = super().check(**kwargs)
4242
errors.extend(self._check_mariadb_dyncol())
4343
errors.extend(self._check_mariadb_version())
4444
errors.extend(self._check_character_set())
@@ -165,7 +165,7 @@ def db_type(self, connection):
165165
return "mediumblob"
166166

167167
def get_transform(self, name):
168-
transform = super(DynamicField, self).get_transform(name)
168+
transform = super().get_transform(name)
169169
if transform:
170170
return transform
171171
if name in self.spec:
@@ -204,7 +204,7 @@ def from_db_value(self, value, expression, connection, context):
204204
return self.to_python(value)
205205

206206
def get_prep_value(self, value):
207-
value = super(DynamicField, self).get_prep_value(value)
207+
value = super().get_prep_value(value)
208208
if isinstance(value, dict):
209209
self.validate_spec(self.spec, value)
210210
return mariadb_dyncol.pack(value)
@@ -237,7 +237,7 @@ def value_to_string(self, obj):
237237
return json.dumps(self.value_from_object(obj))
238238

239239
def deconstruct(self):
240-
name, path, args, kwargs = super(DynamicField, self).deconstruct()
240+
name, path, args, kwargs = super().deconstruct()
241241

242242
bad_paths = (
243243
"django_mysql.models.fields.dynamic.DynamicField",
@@ -289,7 +289,7 @@ class KeyTransform(Transform):
289289

290290
def __init__(self, key_name, data_type, *args, **kwargs):
291291
subspec = kwargs.pop("subspec", None)
292-
super(KeyTransform, self).__init__(*args, **kwargs)
292+
super().__init__(*args, **kwargs)
293293
self.key_name = key_name
294294
self.data_type = data_type
295295

@@ -311,7 +311,7 @@ def as_sql(self, compiler, connection):
311311
)
312312

313313

314-
class KeyTransformFactory(object):
314+
class KeyTransformFactory:
315315
def __init__(self, key_name, data_type, subspec=None):
316316
self.key_name = key_name
317317
self.data_type = data_type

src/django_mysql/models/fields/enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def __init__(self, *args, **kwargs):
3232
# maximum string length
3333
kwargs["max_length"] = int(2 ** 32)
3434

35-
super(EnumField, self).__init__(*args, **kwargs)
35+
super().__init__(*args, **kwargs)
3636

3737
def deconstruct(self):
38-
name, path, args, kwargs = super(EnumField, self).deconstruct()
38+
name, path, args, kwargs = super().deconstruct()
3939

4040
bad_paths = (
4141
"django_mysql.models.fields.enum.EnumField",

src/django_mysql/models/fields/json.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ def __init__(self, *args, **kwargs):
3333
kwargs["default"] = dict
3434
self.json_encoder = kwargs.pop("encoder", self._default_json_encoder)
3535
self.json_decoder = kwargs.pop("decoder", self._default_json_decoder)
36-
super(JSONField, self).__init__(*args, **kwargs)
36+
super().__init__(*args, **kwargs)
3737

3838
def check(self, **kwargs):
39-
errors = super(JSONField, self).check(**kwargs)
39+
errors = super().check(**kwargs)
4040
errors.extend(self._check_default())
4141
errors.extend(self._check_mysql_version())
4242
errors.extend(self._check_json_encoder_decoder())
@@ -116,7 +116,7 @@ def _check_json_encoder_decoder(self):
116116
return errors
117117

118118
def deconstruct(self):
119-
name, path, args, kwargs = super(JSONField, self).deconstruct()
119+
name, path, args, kwargs = super().deconstruct()
120120

121121
bad_paths = (
122122
"django_mysql.models.fields.json.JSONField",
@@ -131,7 +131,7 @@ def db_type(self, connection):
131131
return "json"
132132

133133
def get_transform(self, name):
134-
transform = super(JSONField, self).get_transform(name)
134+
transform = super().get_transform(name)
135135
if transform:
136136
return transform # pragma: no cover
137137
return KeyTransformFactory(name)
@@ -181,15 +181,15 @@ def get_lookup(self, lookup_name):
181181
raise NotImplementedError(
182182
"Lookup '{}' doesn't work with JSONField".format(lookup_name)
183183
)
184-
return super(JSONField, self).get_lookup(lookup_name)
184+
return super().get_lookup(lookup_name)
185185

186186
def value_to_string(self, obj):
187187
return self.value_from_object(obj)
188188

189189
def formfield(self, **kwargs):
190190
defaults = {"form_class": forms.JSONField}
191191
defaults.update(kwargs)
192-
return super(JSONField, self).formfield(**defaults)
192+
return super().formfield(**defaults)
193193

194194

195195
class JSONLength(Transform):
@@ -215,7 +215,7 @@ class JSONLength(Transform):
215215

216216
class KeyTransform(Transform):
217217
def __init__(self, key_name, *args, **kwargs):
218-
super(KeyTransform, self).__init__(*args, **kwargs)
218+
super().__init__(*args, **kwargs)
219219
self.key_name = key_name
220220

221221
def as_sql(self, compiler, connection):
@@ -243,7 +243,7 @@ def compile_json_path(self, key_transforms):
243243
return "".join(path)
244244

245245

246-
class KeyTransformFactory(object):
246+
class KeyTransformFactory:
247247
def __init__(self, key_name):
248248
self.key_name = key_name
249249

0 commit comments

Comments
 (0)