Skip to content

Commit 92abbb9

Browse files
committed
Modernize the code for Python 3.8
With the help of pyupgrade
1 parent b542b56 commit 92abbb9

File tree

11 files changed

+14
-18
lines changed

11 files changed

+14
-18
lines changed

docs/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# flower documentation build configuration file, created by
42
# sphinx-quickstart on Fri Apr 11 17:26:01 2014.
53
#

examples/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def sleep(seconds):
2424

2525
@app.task
2626
def echo(msg, timestamp=False):
27-
return "%s: %s" % (datetime.now(), msg) if timestamp else msg
27+
return "{}: {}".format(datetime.now(), msg) if timestamp else msg
2828

2929

3030
@app.task

flower/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def apply_options(prog_name, argv):
8787
try:
8888
parse_config_file(os.path.abspath(options.conf), final=False)
8989
parse_command_line([prog_name] + argv)
90-
except IOError:
90+
except OSError:
9191
if os.path.basename(options.conf) != DEFAULT_CONFIG_FILE:
9292
raise
9393

flower/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def bugreport(app=None):
1818
app = app or celery.Celery()
1919

2020
# pylint: disable=consider-using-f-string
21-
return 'flower -> flower:%s tornado:%s humanize:%s%s' % (
21+
return 'flower -> flower:{} tornado:{} humanize:{}{}'.format(
2222
__version__,
2323
tornado.version,
2424
getattr(humanize, '__version__', None) or getattr(humanize, 'VERSION'),

flower/utils/broker.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import logging
44
import numbers
5-
import socket
65
import sys
76
from urllib.parse import quote, unquote, urljoin, urlparse
87

@@ -67,7 +66,7 @@ async def queues(self, names):
6766
url, auth_username=username, auth_password=password,
6867
connect_timeout=1.0, request_timeout=2.0,
6968
validate_cert=False)
70-
except (socket.error, httpclient.HTTPError) as e:
69+
except (OSError, httpclient.HTTPError) as e:
7170
logger.error("RabbitMQ management API call failed: %s", e)
7271
return []
7372
finally:
@@ -106,7 +105,7 @@ def _q_for_pri(self, queue, pri):
106105
if pri not in self.priority_steps:
107106
raise ValueError('Priority not in priority steps')
108107
# pylint: disable=consider-using-f-string
109-
return '{0}{1}{2}'.format(*((queue, self.sep, pri) if pri else (queue, '', '')))
108+
return '{}{}{}'.format(*((queue, self.sep, pri) if pri else (queue, '', '')))
110109

111110
async def queues(self, names):
112111
queue_stats = []
@@ -115,7 +114,7 @@ async def queues(self, names):
115114
name, pri) for pri in self.priority_steps]
116115
queue_stats.append({
117116
'name': name,
118-
'messages': sum((self.redis.llen(x) for x in priority_names))
117+
'messages': sum(self.redis.llen(x) for x in priority_names)
119118
})
120119
return queue_stats
121120

flower/utils/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def parse_search_terms(raw_search_value):
2121
if 'kwargs'not in parsed_search:
2222
parsed_search['kwargs'] = {}
2323
try:
24-
key, value = [p.strip() for p in query_part[len('kwargs:'):].split('=')]
24+
key, value = (p.strip() for p in query_part[len('kwargs:'):].split('='))
2525
except ValueError:
2626
continue
2727
parsed_search['kwargs'][key] = preprocess_search_value(value)

flower/views/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ def format_task(self, task):
125125
return task
126126

127127
def get_active_queue_names(self):
128-
queues = set([])
128+
queues = set()
129129
for _, info in self.application.workers.items():
130130
for queue in info.get('active_queues', []):
131131
queues.add(queue['name'])
132132

133133
if not queues:
134-
queues = set([self.capp.conf.task_default_queue]) |\
134+
queues = {self.capp.conf.task_default_queue} |\
135135
{q.name for q in self.capp.conf.task_queues or [] if q.name}
136136
return sorted(queues)

flower/views/workers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def get(self):
7777
@classmethod
7878
def _as_dict(cls, worker):
7979
if hasattr(worker, '_fields'):
80-
return dict((k, getattr(worker, k)) for k in worker._fields)
80+
return {k: getattr(worker, k) for k in worker._fields}
8181
return cls._info(worker)
8282

8383
@classmethod

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def get_requirements(filename):
3131
Programming Language :: Python
3232
Programming Language :: Python :: 3
3333
Programming Language :: Python :: 3 :: Only
34-
Programming Language :: Python :: 3.7
3534
Programming Language :: Python :: 3.8
3635
Programming Language :: Python :: 3.9
3736
Programming Language :: Python :: 3.10

tests/unit/test_command.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_empty_conf(self):
166166
def test_conf_abs(self):
167167
with tempfile.NamedTemporaryFile() as cf:
168168
with self.mock_option('conf', cf.name), self.mock_option('debug', False):
169-
cf.write('debug=True\n'.encode('utf-8'))
169+
cf.write(b'debug=True\n')
170170
cf.flush()
171171
apply_options('flower', argv=['--conf=%s' % cf.name])
172172
self.assertEqual(cf.name, options.conf)
@@ -175,7 +175,7 @@ def test_conf_abs(self):
175175
def test_conf_relative(self):
176176
with tempfile.NamedTemporaryFile(dir='.') as cf:
177177
with self.mock_option('conf', cf.name), self.mock_option('debug', False):
178-
cf.write('debug=True\n'.encode('utf-8'))
178+
cf.write(b'debug=True\n')
179179
cf.flush()
180180
apply_options('flower', argv=['--conf=%s' % os.path.basename(cf.name)])
181181
self.assertTrue(options.debug)
@@ -184,7 +184,7 @@ def test_conf_relative(self):
184184
def test_all_options_documented(self):
185185
def grep(patter, filename):
186186
return int(subprocess.check_output(
187-
'grep "%s" %s|wc -l' % (patter, filename), shell=True))
187+
'grep "{}" {}|wc -l'.format(patter, filename), shell=True))
188188

189189
defined = grep('^define(', 'flower/options.py')
190190
documented = grep('^~~', 'docs/config.rst')

0 commit comments

Comments
 (0)