Skip to content

Commit

Permalink
Modernise Python syntax (#635)
Browse files Browse the repository at this point in the history
* Modernise Python syntax

* Modernise Python syntax -- Updated super()

Co-authored-by: Jannis Leidel <[email protected]>
  • Loading branch information
smithdc1 and jezdez authored Nov 23, 2020
1 parent 8480bc6 commit 9529d68
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 43 deletions.
7 changes: 3 additions & 4 deletions sorl/thumbnail/admin/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AdminImageWidget(forms.ClearableFileInput):
template_with_clear = '<label>%(clear_checkbox_label)s: %(clear)s</label>'

def render(self, name, value, attrs=None, **kwargs):
output = super(AdminImageWidget, self).render(name, value, attrs, **kwargs)
output = super().render(name, value, attrs, **kwargs)
if value and hasattr(value, 'url'):
ext = 'JPEG'
try:
Expand Down Expand Up @@ -50,7 +50,7 @@ def render(self, name, value, attrs=None, **kwargs):
return mark_safe(output)


class AdminImageMixin(object):
class AdminImageMixin:
"""
This is a mix-in for InlineModelAdmin subclasses to make ``ImageField``
show nicer form widget
Expand All @@ -59,5 +59,4 @@ class AdminImageMixin(object):
def formfield_for_dbfield(self, db_field, request, **kwargs):
if isinstance(db_field, ImageField):
return db_field.formfield(widget=AdminImageWidget)
sup = super(AdminImageMixin, self)
return sup.formfield_for_dbfield(db_field, request, **kwargs)
return super().formfield_for_dbfield(db_field, request, **kwargs)
2 changes: 1 addition & 1 deletion sorl/thumbnail/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}


class ThumbnailBackend(object):
class ThumbnailBackend:
"""
The main class for sorl-thumbnail, you can subclass this if you for example
want to change the way destination filename is generated.
Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/engines/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sorl.thumbnail.parsers import parse_cropbox


class EngineBase(object):
class EngineBase:
"""
ABC for Thumbnail engines, methods are static
"""
Expand Down
4 changes: 2 additions & 2 deletions sorl/thumbnail/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def delete_file(self, instance, sender, **kwargs):
def formfield(self, **kwargs):
defaults = {'form_class': ImageFormField}
defaults.update(kwargs)
return super(ImageField, self).formfield(**defaults)
return super().formfield(**defaults)

def save_form_data(self, instance, data):
if data is not None:
Expand All @@ -49,7 +49,7 @@ def to_python(self, data):
Checks that the file-upload field data contains a valid image (GIF,
JPG, PNG, possibly others -- whatever the engine supports).
"""
f = super(ImageFormField, self).to_python(data)
f = super().to_python(data)
if f is None:
return None

Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SortedJSONEncoder(json.JSONEncoder):

def __init__(self, **kwargs):
kwargs['sort_keys'] = True
super(SortedJSONEncoder, self).__init__(**kwargs)
super().__init__(**kwargs)


def toint(number):
Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _setup(self):
return image_file


class BaseImageFile(object):
class BaseImageFile:
size = []

def exists(self):
Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/kvstores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def del_prefix(key):
return key.split('||')[-1]


class KVStoreBase(object):
class KVStoreBase:
def get(self, image_file):
"""
Gets the ``image_file`` from store. Returns ``None`` if not found.
Expand Down
4 changes: 2 additions & 2 deletions sorl/thumbnail/kvstores/cached_db_kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from sorl.thumbnail.models import KVStore as KVStoreModel


class EMPTY_VALUE(object):
class EMPTY_VALUE:
pass


class KVStore(KVStoreBase):
def __init__(self):
super(KVStore, self).__init__()
super().__init__()

@property
def cache(self):
Expand Down
4 changes: 2 additions & 2 deletions sorl/thumbnail/kvstores/dbm_kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def unlock(f):
fcntl.lockf(f.fileno(), fcntl.LOCK_UN)


class DBMContext(object):
class DBMContext:
"""
A context manager to access the key-value store in a concurrent-safe manner.
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ class KVStore(KVStoreBase):
# environments.

def __init__(self):
super(KVStore, self).__init__()
super().__init__()
self.filename = settings.THUMBNAIL_DBM_FILE
self.mode = settings.THUMBNAIL_DBM_MODE

Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/kvstores/dynamodb_kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class KVStore(KVStoreBase):
def __init__(self):
super(KVStore, self).__init__()
super().__init__()
region = settings.AWS_REGION_NAME
access_key = settings.AWS_ACCESS_KEY_ID
secret = settings.AWS_SECRET_ACCESS_KEY
Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/kvstores/redis_kvstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class KVStore(KVStoreBase):
def __init__(self):
super(KVStore, self).__init__()
super().__init__()

if hasattr(settings, 'THUMBNAIL_REDIS_URL'):
self.connection = redis.from_url(settings.THUMBNAIL_REDIS_URL)
Expand Down
10 changes: 5 additions & 5 deletions tests/thumbnail_tests/kvstore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sorl.thumbnail.kvstores.cached_db_kvstore import KVStore


class KVlogHandler(object):
class KVlogHandler:
_log = []
_active = False

Expand All @@ -22,18 +22,18 @@ def log(self, s):
kvlog = KVlogHandler()


class TestKvStoreMixin(object):
class TestKvStoreMixin:
def get(self, *args, **kwargs):
kvlog.log('get')
return super(TestKvStoreMixin, self).get(*args, **kwargs)
return super().get(*args, **kwargs)

def set(self, *args, **kwargs):
kvlog.log('set')
return super(TestKvStoreMixin, self).set(*args, **kwargs)
return super().set(*args, **kwargs)

def delete(self, *args, **kwargs):
kvlog.log('delete')
return super(TestKvStoreMixin, self).delete(*args, **kwargs)
return super().delete(*args, **kwargs)


class TestKVStore(TestKvStoreMixin, KVStore):
Expand Down
30 changes: 15 additions & 15 deletions tests/thumbnail_tests/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MockLoggingHandler(logging.Handler):

def __init__(self, *args, **kwargs):
self.reset()
super(MockLoggingHandler, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def emit(self, record):
self.messages[record.levelname.lower()].append(record.getMessage())
Expand All @@ -20,58 +20,58 @@ def reset(self):
slog = logging.getLogger('slog')


class TestStorageMixin(object):
class TestStorageMixin:
def open(self, name, *args, **kwargs):
slog.debug('open: %s' % name)
return super(TestStorageMixin, self).open(name, *args, **kwargs)
return super().open(name, *args, **kwargs)

def save(self, name, *args, **kwargs):
slog.debug('save: %s' % name)
return super(TestStorageMixin, self).save(name, *args, **kwargs)
return super().save(name, *args, **kwargs)

def get_valid_name(self, name, *args, **kwargs):
slog.debug('get_valid_name: %s' % name)
return super(TestStorageMixin, self).get_valid_name(name, *args, **kwargs)
return super().get_valid_name(name, *args, **kwargs)

def get_available_name(self, name, *args, **kwargs):
slog.debug('get_available_name: %s' % name)
return super(TestStorageMixin, self).get_available_name(name, *args, **kwargs)
return super().get_available_name(name, *args, **kwargs)

def path(self, name, *args, **kwargs):
# slog.debug('path: %s' % name)
return super(TestStorageMixin, self).path(name, *args, **kwargs)
return super().path(name, *args, **kwargs)

def delete(self, name, *args, **kwargs):
slog.debug('delete: %s' % name)
return super(TestStorageMixin, self).delete(name, *args, **kwargs)
return super().delete(name, *args, **kwargs)

def exists(self, name, *args, **kwargs):
slog.debug('exists: %s' % name)
return super(TestStorageMixin, self).exists(name, *args, **kwargs)
return super().exists(name, *args, **kwargs)

def listdir(self, name, *args, **kwargs):
slog.debug('listdir: %s' % name)
return super(TestStorageMixin, self).listdir(name, *args, **kwargs)
return super().listdir(name, *args, **kwargs)

def size(self, name, *args, **kwargs):
slog.debug('size: %s' % name)
return super(TestStorageMixin, self).size(name, *args, **kwargs)
return super().size(name, *args, **kwargs)

def url(self, name, *args, **kwargs):
# slog.debug('url: %s' % name)
return super(TestStorageMixin, self).url(name, *args, **kwargs)
return super().url(name, *args, **kwargs)

def accessed_time(self, name, *args, **kwargs):
slog.debug('accessed_time: %s' % name)
return super(TestStorageMixin, self).accessed_time(name, *args, **kwargs)
return super().accessed_time(name, *args, **kwargs)

def created_time(self, name, *args, **kwargs):
slog.debug('created_time: %s' % name)
return super(TestStorageMixin, self).created_time(name, *args, **kwargs)
return super().created_time(name, *args, **kwargs)

def modified_time(self, name, *args, **kwargs):
slog.debug('modified_time: %s' % name)
return super(TestStorageMixin, self).modified_time(name, *args, **kwargs)
return super().modified_time(name, *args, **kwargs)


class TestStorage(TestStorageMixin, FileSystemStorage):
Expand Down
4 changes: 2 additions & 2 deletions tests/thumbnail_tests/test_alternative_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class AlternativeResolutionsTest(BaseStorageTestCase):

def setUp(self):
settings.THUMBNAIL_ALTERNATIVE_RESOLUTIONS = [1.5, 2]
super(AlternativeResolutionsTest, self).setUp()
super().setUp()
self.maxDiff = None

def tearDown(self):
super(AlternativeResolutionsTest, self).tearDown()
super().tearDown()
settings.THUMBNAIL_ALTERNATIVE_RESOLUTIONS = []

def test_retina(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/thumbnail_tests/test_engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_falsey_file_argument(self):

class CropTestCase(BaseTestCase):
def setUp(self):
super(CropTestCase, self).setUp()
super().setUp()

# portrait
name = 'portrait.jpg'
Expand Down Expand Up @@ -393,7 +393,7 @@ def test_crop_image_with_icc_profile(self):
# so we cannot test for pixel color
class CropBoxTestCase(BaseTestCase):
def setUp(self):
super(CropBoxTestCase, self).setUp()
super().setUp()

# portrait
name = 'portrait.jpg'
Expand Down Expand Up @@ -539,7 +539,7 @@ def setUp(self):
self.BACKEND = get_module_class(settings.THUMBNAIL_BACKEND)()

def tearDown(self):
super(DummyTestCase, self).tearDown()
super().tearDown()
settings.THUMBNAIL_ALTERNATIVE_RESOLUTIONS = []

def test_dummy_tags(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/thumbnail_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_open_fds_count():
return nprocs


class FakeFile(object):
class FakeFile:
"""
Used to test the _get_format method.
"""
Expand Down

0 comments on commit 9529d68

Please sign in to comment.