Skip to content

Commit 00fc485

Browse files
committed
Syntax modernisations for Python 3.10
1 parent d458d22 commit 00fc485

File tree

9 files changed

+26
-29
lines changed

9 files changed

+26
-29
lines changed

cacheback/base.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def to_bytestring(value):
2828
:returns: a bytestring
2929
"""
3030
if isinstance(value, DjangoModel):
31-
return ('%s:%s' % (value.__class__, hash(value))).encode('utf-8')
31+
return (f'{value.__class__}:{hash(value)}').encode('utf-8')
3232
if isinstance(value, str):
3333
return value.encode('utf8')
3434
if isinstance(value, bytes):
3535
return value
3636
return bytes(str(value), 'utf8')
3737

3838

39-
class Job(object):
39+
class Job:
4040
"""
4141
A cached read job.
4242
@@ -90,7 +90,7 @@ class Job(object):
9090

9191
@property
9292
def class_path(self):
93-
return '%s.%s' % (self.__module__, self.__class__.__name__)
93+
return f'{self.__module__}.{self.__class__.__name__}'
9494

9595
def __init__(self):
9696
self.cache_alias = self.cache_alias or getattr(
@@ -402,11 +402,11 @@ def key(self, *args, **kwargs):
402402
return self.class_path
403403
try:
404404
if args and not kwargs:
405-
return "%s:%s" % (self.class_path, self.hash(args))
405+
return f"{self.class_path}:{self.hash(args)}"
406406
# The line might break if your passed values are un-hashable. If
407407
# it does, you need to override this method and implement your own
408408
# key algorithm.
409-
return "%s:%s:%s:%s" % (
409+
return "{}:{}:{}:{}".format(
410410
self.class_path,
411411
self.hash(args),
412412
self.hash([k for k in sorted(kwargs)]),

cacheback/jobs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(
1919
task_options=None,
2020
set_data_kwarg=None,
2121
):
22-
super(FunctionJob, self).__init__()
22+
super().__init__()
2323
if lifetime is not None:
2424
self.lifetime = int(lifetime)
2525
if fetch_on_miss is not None:
@@ -43,7 +43,7 @@ def get_init_kwargs(self):
4343
def prepare_args(self, fn, *args):
4444
# Convert function into "module:name" form so that is can be pickled and
4545
# then re-imported.
46-
return ("%s:%s" % (fn.__module__, fn.__name__),) + args
46+
return (f"{fn.__module__}:{fn.__name__}",) + args
4747

4848
def fetch(self, fn_string, *args, **kwargs):
4949
# Import function from string representation
@@ -67,7 +67,7 @@ def __init__(
6767
"""
6868
:model: The model class to use
6969
"""
70-
super(QuerySetJob, self).__init__()
70+
super().__init__()
7171
self.model = model
7272
if lifetime is not None:
7373
self.lifetime = lifetime
@@ -82,7 +82,7 @@ def get_init_kwargs(self):
8282
return {'model': self.model, 'lifetime': self.lifetime, 'cache_alias': self.cache_alias}
8383

8484
def key(self, *args, **kwargs):
85-
return "%s-%s" % (self.model.__name__, super(QuerySetJob, self).key(*args, **kwargs))
85+
return f"{self.model.__name__}-{super().key(*args, **kwargs)}"
8686

8787

8888
class QuerySetGetJob(QuerySetJob):

cacheback/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,4 @@ def enqueue_task(kwargs, task_options=None):
5858
elif task_queue == 'celery' and celery_refresh_cache is not None:
5959
return celery_refresh_cache.apply_async(kwargs=kwargs, **task_options or {})
6060

61-
raise ImproperlyConfigured('Unkown task queue configured: {0}'.format(task_queue))
61+
raise ImproperlyConfigured(f'Unkown task queue configured: {task_queue}')

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-cacheback documentation build configuration file, created by
43
# sphinx-quickstart on Mon Jul 30 21:40:46 2012.
@@ -50,8 +49,8 @@
5049
master_doc = 'index'
5150

5251
# General information about the project.
53-
project = u'django-cacheback'
54-
copyright = u'2012, David Winterbottom'
52+
project = 'django-cacheback'
53+
copyright = '2012, David Winterbottom'
5554

5655
# The version info for the project you're documenting, acts as replacement for
5756
# |version| and |release|, also used in various other places throughout the
@@ -194,8 +193,8 @@
194193
# Grouping the document tree into LaTeX files. List of tuples
195194
# (source start file, target name, title, author, documentclass [howto/manual]).
196195
latex_documents = [
197-
('index', 'django-cacheback', u'django-cacheback Documentation',
198-
u'David Winterbottom', 'manual'),
196+
('index', 'django-cacheback', 'django-cacheback Documentation',
197+
'David Winterbottom', 'manual'),
199198
]
200199

201200
# The name of an image file (relative to this directory) to place at the top of
@@ -224,8 +223,8 @@
224223
# One entry per manual page. List of tuples
225224
# (source start file, name, description, authors, manual section).
226225
man_pages = [
227-
('index', 'django-cacheback', u'django-cacheback Documentation',
228-
[u'David Winterbottom'], 1)
226+
('index', 'django-cacheback', 'django-cacheback Documentation',
227+
['David Winterbottom'], 1)
229228
]
230229

231230
# If true, show URL addresses after external links.
@@ -238,8 +237,8 @@
238237
# (source start file, target name, title, author,
239238
# dir menu entry, description, category)
240239
texinfo_documents = [
241-
('index', 'django-cacheback', u'django-cacheback Documentation',
242-
u'David Winterbottom', 'django-cacheback', 'One line description of project.',
240+
('index', 'django-cacheback', 'django-cacheback Documentation',
241+
'David Winterbottom', 'django-cacheback', 'One line description of project.',
243242
'Miscellaneous'),
244243
]
245244

sandbox/dummyapp/migrations/0001_initial.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
21
# Generated by Django 1.9 on 2015-12-12 20:02
3-
from __future__ import unicode_literals
42

53
from django.db import migrations, models
64

sandbox/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,5 @@
182182
}
183183
}
184184

185-
CACHEBACK_TASK_QUEUE = dict([(q, q) for q in ('celery', 'rq')]).get(
185+
CACHEBACK_TASK_QUEUE = {q: q for q in ('celery', 'rq')}.get(
186186
os.environ.get('QUEUE', ''), 'celery')

tests/test_base_job.py

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

1313
class DummyJob(Job):
1414
def fetch(self, param):
15-
return ('JOB-EXECUTED:{0}'.format(param), timezone.now())
15+
return (f'JOB-EXECUTED:{param}', timezone.now())
1616

1717

1818
class CacheAliasDummyJob(DummyJob):

tests/test_decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ class OtherFunctionJob(FunctionJob):
1010

1111
@cacheback(fetch_on_miss=False, job_class=OtherFunctionJob)
1212
def no_fetch_miss_function(param):
13-
return 'JOB-EXECUTED:{0}'.format(param)
13+
return f'JOB-EXECUTED:{param}'
1414

1515

1616
@cacheback(lifetime=30, fetch_on_miss=True)
1717
def fetch_miss_function(param):
18-
return 'JOB-EXECUTED:{0}'.format(param)
18+
return f'JOB-EXECUTED:{param}'
1919

2020

2121
@cacheback(cache_alias='secondary', fetch_on_miss=True)
2222
def fetch_cache_alias_function(param):
23-
return 'JOB-EXECUTED:{0}'.format(param)
23+
return f'JOB-EXECUTED:{param}'
2424

2525

2626
@cacheback(set_data_kwarg='my_data')
2727
def custom_payload_label_function(param):
28-
return 'JOB-EXECUTED:{0}'.format(param)
28+
return f'JOB-EXECUTED:{param}'
2929

3030

3131
@pytest.mark.usefixtures('cleared_cache', scope='function')

tests/test_jobs.py

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

77

88
def dummy_function(param):
9-
return 'JOB-EXECUTED:{0}'.format(param)
9+
return f'JOB-EXECUTED:{param}'
1010

1111

1212
@cacheback()
1313
def decorated_dummy_function(param):
14-
return 'JOB-EXECUTED:{0}'.format(param)
14+
return f'JOB-EXECUTED:{param}'
1515

1616

1717
@pytest.mark.usefixtures('cleared_cache', scope='function')

0 commit comments

Comments
 (0)