Skip to content

Commit 8593ba1

Browse files
Apply ruff/pyupgrade rule UP032
UP032 Use f-string instead of `format` call
1 parent 27b5bbe commit 8593ba1

File tree

14 files changed

+29
-40
lines changed

14 files changed

+29
-40
lines changed

examples/bench/echoclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
addr = args.addr.split(':')
4646
addr[1] = int(addr[1])
4747
addr = tuple(addr)
48-
print('will connect to: {}'.format(addr))
48+
print(f'will connect to: {addr}')
4949

5050
MSGSIZE = args.msize
5151
REQSIZE = MSGSIZE * args.mpr

examples/bench/echoserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ async def print_debug(loop):
139139
addr[1] = int(addr[1])
140140
addr = tuple(addr)
141141

142-
print('serving on: {}'.format(addr))
142+
print(f'serving on: {addr}')
143143

144144
server_context = None
145145
if args.ssl:

examples/bench/rlserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def print_debug(loop):
7171
addr = tuple(addr)
7272

7373
print('readline performance test')
74-
print('serving on: {}'.format(addr))
74+
print(f'serving on: {addr}')
7575

7676
print('using asyncio/streams')
7777
if unix:

setup.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
MODULES_CFLAGS = [os.getenv('UVLOOP_OPT_CFLAGS', '-O2')]
2727
_ROOT = pathlib.Path(__file__).parent
2828
LIBUV_DIR = str(_ROOT / 'vendor' / 'libuv')
29-
LIBUV_BUILD_DIR = str(_ROOT / 'build' / 'libuv-{}'.format(MACHINE))
29+
LIBUV_BUILD_DIR = str(_ROOT / 'build' / f'libuv-{MACHINE}')
3030

3131

3232
def _libuv_build_env():
@@ -118,15 +118,12 @@ def finalize_options(self):
118118
import Cython
119119
except ImportError:
120120
raise RuntimeError(
121-
'please install {} to compile uvloop from source'.format(
122-
CYTHON_DEPENDENCY))
121+
f'please install {CYTHON_DEPENDENCY} to compile uvloop from source')
123122

124123
cython_dep = pkg_resources.Requirement.parse(CYTHON_DEPENDENCY)
125124
if Cython.__version__ not in cython_dep:
126125
raise RuntimeError(
127-
'uvloop requires {}, got Cython=={}'.format(
128-
CYTHON_DEPENDENCY, Cython.__version__
129-
))
126+
f'uvloop requires {CYTHON_DEPENDENCY}, got Cython=={Cython.__version__}')
130127

131128
from Cython.Build import cythonize
132129

@@ -183,7 +180,7 @@ def build_libuv(self):
183180
njobs = len(os.sched_getaffinity(0))
184181
except AttributeError:
185182
njobs = os.cpu_count()
186-
j_flag = '-j{}'.format(njobs or 1)
183+
j_flag = f'-j{njobs or 1}'
187184
c_flag = "CFLAGS={}".format(env['CFLAGS'])
188185
subprocess.run(
189186
['make', j_flag, c_flag],

tests/test_aiohttp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async def on_shutdown(app):
9595
async def client():
9696
async with aiohttp.ClientSession() as client:
9797
async with client.ws_connect(
98-
'http://127.0.0.1:{}'.format(port)) as ws:
98+
f'http://127.0.0.1:{port}') as ws:
9999
await ws.send_str("hello")
100100
async for msg in ws:
101101
assert msg.data == "hello"

tests/test_context.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ def get_buffer(self, sizehint):
6161
if self.buffered_ctx is None:
6262
self.buffered_ctx = self.cvar.get()
6363
elif self.cvar.get() != self.buffered_ctx:
64-
self.data_received_fut.set_exception(ValueError("{} != {}".format(
65-
self.buffered_ctx, self.cvar.get(),
66-
)))
64+
self.data_received_fut.set_exception(ValueError(f"{self.buffered_ctx} != {self.cvar.get()}"))
6765
return bytearray(65536)
6866

6967
def buffer_updated(self, nbytes):
@@ -72,9 +70,7 @@ def buffer_updated(self, nbytes):
7270
self.data_received_fut.set_result(self.cvar.get())
7371
else:
7472
self.data_received_fut.set_exception(
75-
ValueError("{} != {}".format(
76-
self.buffered_ctx, self.cvar.get(),
77-
))
73+
ValueError(f"{self.buffered_ctx} != {self.cvar.get()}")
7874
)
7975

8076

@@ -202,16 +198,16 @@ def fut_on_done(fut):
202198
for j in range(2):
203199
fut = self.loop.create_future()
204200
fut.add_done_callback(fut_on_done)
205-
cvar.set('yes{}'.format(j))
201+
cvar.set(f'yes{j}')
206202
self.loop.call_soon(fut.set_result, None)
207203
await fut
208-
self.assertEqual(cvar.get(), 'yes{}'.format(j))
204+
self.assertEqual(cvar.get(), f'yes{j}')
209205

210206
for i in range(3):
211207
# Test that task passed its context to add_done_callback:
212-
cvar.set('yes{}-{}'.format(i, j))
208+
cvar.set(f'yes{i}-{j}')
213209
await asyncio.sleep(0.001)
214-
self.assertEqual(cvar.get(), 'yes{}-{}'.format(i, j))
210+
self.assertEqual(cvar.get(), f'yes{i}-{j}')
215211

216212
task = self.loop.create_task(main())
217213
self.loop.run_until_complete(task)

tests/test_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ async def test():
192192
stdout=subprocess.PIPE)
193193

194194
pid = proc.pid
195-
expected_result = '{}\n'.format(pid).encode()
195+
expected_result = f'{pid}\n'.encode()
196196

197197
out, err = await proc.communicate()
198198
self.assertEqual(out, expected_result)

tests/test_process_spawning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def spawn_process():
100100
t.start()
101101
t.join(timeout=10.0)
102102
if t.is_alive():
103-
raise Exception('process freeze detected at {}'
104-
.format(iteration))
103+
raise Exception(f'process freeze detected at {iteration}'
104+
)
105105

106106
return True
107107

tests/test_signals.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ def handler_hup():
297297

298298
def test_signals_invalid_signal(self):
299299
with self.assertRaisesRegex(RuntimeError,
300-
'sig {} cannot be caught'.format(
301-
signal.SIGKILL)):
300+
f'sig {signal.SIGKILL} cannot be caught'):
302301

303302
self.loop.add_signal_handler(signal.SIGKILL, lambda *a: None)
304303

tests/test_sourcecode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_flake8(self):
3333
output += '\n'
3434
output += ex.stderr.decode()
3535
raise AssertionError(
36-
'flake8 validation failed: {}\n{}'.format(ex, output)
36+
f'flake8 validation failed: {ex}\n{output}'
3737
) from None
3838

3939
def test_mypy(self):
@@ -66,5 +66,5 @@ def test_mypy(self):
6666
output += '\n'
6767
output += ex.stderr.decode()
6868
raise AssertionError(
69-
'mypy validation failed: {}\n{}'.format(ex, output)
69+
f'mypy validation failed: {ex}\n{output}'
7070
) from None

0 commit comments

Comments
 (0)