Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e08e823
Apply ruff/flake8-bugbear rule B009
DimitriPapadopoulos Oct 13, 2025
8a28345
Apply ruff/flake8-executable rule EXE001
DimitriPapadopoulos Oct 13, 2025
87b34ed
Apply ruff/flake8-pie rule PIE810
DimitriPapadopoulos Oct 13, 2025
80a6488
Apply ruff/flake8-slots rule SLOT000
DimitriPapadopoulos Oct 13, 2025
102dcf3
Apply ruff/Perflint rule PERF401
DimitriPapadopoulos Oct 13, 2025
c706786
Apply ruff/Pyflakes rule F401
DimitriPapadopoulos Oct 13, 2025
d5120ba
Apply ruff/Pylint rule PLC0208
DimitriPapadopoulos Oct 13, 2025
32cc013
Apply ruff/Pylint rule PLR1722
DimitriPapadopoulos Oct 13, 2025
501d180
Apply ruff/Pylint rule PLR5501
DimitriPapadopoulos Oct 13, 2025
6a3742a
Apply ruff/Pylint rule PLR6201
DimitriPapadopoulos Oct 13, 2025
e5721cf
Apply ruff/pyupgrade rule UP006
DimitriPapadopoulos Oct 13, 2025
5a51a48
Apply ruff/pyupgrade rule UP007
DimitriPapadopoulos Oct 13, 2025
7ad13a3
Apply ruff/pyupgrade rule UP020
DimitriPapadopoulos Oct 13, 2025
555ebd5
Apply ruff/pyupgrade rule UP022
DimitriPapadopoulos Oct 13, 2025
91fb846
Apply ruff/pyupgrade rule UP024
DimitriPapadopoulos Oct 13, 2025
6352a52
Apply ruff/pyupgrade rule UP031
DimitriPapadopoulos Oct 13, 2025
855eb73
Apply ruff/pyupgrade rule UP032
DimitriPapadopoulos Oct 13, 2025
37f452b
Apply ruff/pyupgrade rule UP045
DimitriPapadopoulos Oct 13, 2025
d0bdaed
Apply ruff rule RUF036
DimitriPapadopoulos Oct 13, 2025
117961e
Apply ruff rule RUF046
DimitriPapadopoulos Oct 13, 2025
0aa3e81
Pacify flake8
DimitriPapadopoulos Oct 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .github/release_log.py
100644 → 100755
Empty file.
Empty file modified docs/conf.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion examples/bench/echoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
addr = args.addr.split(':')
addr[1] = int(addr[1])
addr = tuple(addr)
print('will connect to: {}'.format(addr))
print(f'will connect to: {addr}')

MSGSIZE = args.msize
REQSIZE = MSGSIZE * args.mpr
Expand Down
11 changes: 6 additions & 5 deletions examples/bench/echoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import socket
import ssl
import sys


PRINT = 0
Expand Down Expand Up @@ -138,7 +139,7 @@ async def print_debug(loop):
addr[1] = int(addr[1])
addr = tuple(addr)

print('serving on: {}'.format(addr))
print(f'serving on: {addr}')

server_context = None
if args.ssl:
Expand All @@ -159,11 +160,11 @@ async def print_debug(loop):
if args.streams:
if args.proto:
print('cannot use --stream and --proto simultaneously')
exit(1)
sys.exit(1)

if args.buffered:
print('cannot use --stream and --buffered simultaneously')
exit(1)
sys.exit(1)

print('using asyncio/streams')
if unix:
Expand All @@ -178,7 +179,7 @@ async def print_debug(loop):
elif args.proto:
if args.streams:
print('cannot use --stream and --proto simultaneously')
exit(1)
sys.exit(1)

if args.buffered:
print('using buffered protocol')
Expand All @@ -197,7 +198,7 @@ async def print_debug(loop):
else:
if args.ssl:
print('cannot use SSL for loop.sock_* methods')
exit(1)
sys.exit(1)

print('using sock_recv/sock_sendall')
loop.create_task(echo_server(loop, addr, unix))
Expand Down
2 changes: 1 addition & 1 deletion examples/bench/rlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def print_debug(loop):
addr = tuple(addr)

print('readline performance test')
print('serving on: {}'.format(addr))
print(f'serving on: {addr}')

print('using asyncio/streams')
if unix:
Expand Down
17 changes: 9 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
if vi < (3, 8):
raise RuntimeError('uvloop requires Python 3.8 or greater')

if sys.platform in ('win32', 'cygwin', 'cli'):
if sys.platform in {'win32', 'cygwin', 'cli'}:
raise RuntimeError('uvloop does not support Windows at the moment')

import os
Expand All @@ -26,7 +26,7 @@
MODULES_CFLAGS = [os.getenv('UVLOOP_OPT_CFLAGS', '-O2')]
_ROOT = pathlib.Path(__file__).parent
LIBUV_DIR = str(_ROOT / 'vendor' / 'libuv')
LIBUV_BUILD_DIR = str(_ROOT / 'build' / 'libuv-{}'.format(MACHINE))
LIBUV_BUILD_DIR = str(_ROOT / 'build' / f'libuv-{MACHINE}')


def _libuv_build_env():
Expand Down Expand Up @@ -118,15 +118,16 @@ def finalize_options(self):
import Cython
except ImportError:
raise RuntimeError(
'please install {} to compile uvloop from source'.format(
CYTHON_DEPENDENCY))
f'please install {CYTHON_DEPENDENCY} to compile uvloop '
'from source'
)

cython_dep = pkg_resources.Requirement.parse(CYTHON_DEPENDENCY)
if Cython.__version__ not in cython_dep:
raise RuntimeError(
'uvloop requires {}, got Cython=={}'.format(
CYTHON_DEPENDENCY, Cython.__version__
))
f'uvloop requires {CYTHON_DEPENDENCY}, '
f'got Cython=={Cython.__version__}'
)

from Cython.Build import cythonize

Expand Down Expand Up @@ -183,7 +184,7 @@ def build_libuv(self):
njobs = len(os.sched_getaffinity(0))
except AttributeError:
njobs = os.cpu_count()
j_flag = '-j{}'.format(njobs or 1)
j_flag = f'-j{njobs or 1}'
c_flag = "CFLAGS={}".format(env['CFLAGS'])
subprocess.run(
['make', j_flag, c_flag],
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async def on_shutdown(app):
async def client():
async with aiohttp.ClientSession() as client:
async with client.ws_connect(
'http://127.0.0.1:{}'.format(port)) as ws:
f'http://127.0.0.1:{port}') as ws:
await ws.send_str("hello")
async for msg in ws:
assert msg.data == "hello"
Expand Down
6 changes: 3 additions & 3 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def cb():

for i in range(8):
self.loop.call_later(0.06 + 0.01, cb) # 0.06999999999999999
started = int(round(self.loop.time() * 1000))
started = round(self.loop.time() * 1000)
self.loop.run_forever()
finished = int(round(self.loop.time() * 1000))
finished = round(self.loop.time() * 1000)
self.assertGreaterEqual(finished - started, 69)

def test_call_at(self):
Expand Down Expand Up @@ -770,7 +770,7 @@ def test_loop_call_later_handle_cancelled(self):

def test_loop_std_files_cloexec(self):
# See https://github.com/MagicStack/uvloop/issues/40 for details.
for fd in {0, 1, 2}:
for fd in (0, 1, 2):
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
self.assertFalse(flags & fcntl.FD_CLOEXEC)

Expand Down
18 changes: 8 additions & 10 deletions tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def get_buffer(self, sizehint):
if self.buffered_ctx is None:
self.buffered_ctx = self.cvar.get()
elif self.cvar.get() != self.buffered_ctx:
self.data_received_fut.set_exception(ValueError("{} != {}".format(
self.buffered_ctx, self.cvar.get(),
)))
self.data_received_fut.set_exception(
ValueError(f"{self.buffered_ctx} != {self.cvar.get()}")
)
return bytearray(65536)

def buffer_updated(self, nbytes):
Expand All @@ -72,9 +72,7 @@ def buffer_updated(self, nbytes):
self.data_received_fut.set_result(self.cvar.get())
else:
self.data_received_fut.set_exception(
ValueError("{} != {}".format(
self.buffered_ctx, self.cvar.get(),
))
ValueError(f"{self.buffered_ctx} != {self.cvar.get()}")
)


Expand Down Expand Up @@ -202,16 +200,16 @@ def fut_on_done(fut):
for j in range(2):
fut = self.loop.create_future()
fut.add_done_callback(fut_on_done)
cvar.set('yes{}'.format(j))
cvar.set(f'yes{j}')
self.loop.call_soon(fut.set_result, None)
await fut
self.assertEqual(cvar.get(), 'yes{}'.format(j))
self.assertEqual(cvar.get(), f'yes{j}')

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

task = self.loop.create_task(main())
self.loop.run_until_complete(task)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ def test_cython_coro_is_coroutine(self):

coro_fmt = _format_coroutine(coro)
self.assertTrue(
coro_fmt.startswith('_test_coroutine_1() done')
or coro_fmt.startswith('_test_coroutine_1() running')
coro_fmt.startswith(
('_test_coroutine_1() done', '_test_coroutine_1() running')
)
)
self.assertEqual(_test_coroutine_1.__qualname__, '_test_coroutine_1')
self.assertEqual(_test_coroutine_1.__name__, '_test_coroutine_1')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def test_getaddrinfo_close_loop(self):
try:
# Check that we have internet connection
socket.getaddrinfo('example.com', 80)
except socket.error:
except OSError:
raise unittest.SkipTest

async def run():
Expand Down
7 changes: 4 additions & 3 deletions tests/test_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ def run_pool_test(self, pool_factory):
async def run():
pool = pool_factory()
with pool:
coros = []
for i in range(0, 10):
coros.append(self.loop.run_in_executor(pool, fib, i))
coros = [
self.loop.run_in_executor(pool, fib, i)
for i in range(0, 10)
]
res = await asyncio.gather(*coros)
self.assertEqual(res, fib10)
await asyncio.sleep(0.01)
Expand Down
13 changes: 6 additions & 7 deletions tests/test_pipes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import io
import os
import socket

Expand Down Expand Up @@ -74,7 +73,7 @@ def test_read_pipe(self):
proto = MyReadPipeProto(loop=self.loop)

rpipe, wpipe = os.pipe()
pipeobj = io.open(rpipe, 'rb', 1024)
pipeobj = open(rpipe, 'rb', 1024)

async def connect():
t, p = await self.loop.connect_read_pipe(
Expand Down Expand Up @@ -106,7 +105,7 @@ def test_read_pty_output(self):
proto = MyReadPipeProto(loop=self.loop)

master, slave = os.openpty()
master_read_obj = io.open(master, 'rb', 0)
master_read_obj = open(master, 'rb', 0)

async def connect():
t, p = await self.loop.connect_read_pipe(
Expand Down Expand Up @@ -142,7 +141,7 @@ async def connect():
def test_write_pipe(self):
rpipe, wpipe = os.pipe()
os.set_blocking(rpipe, False)
pipeobj = io.open(wpipe, 'wb', 1024)
pipeobj = open(wpipe, 'wb', 1024)

proto = MyWritePipeProto(loop=self.loop)
connect = self.loop.connect_write_pipe(lambda: proto, pipeobj)
Expand Down Expand Up @@ -185,7 +184,7 @@ def test_write_pipe_disconnect_on_close(self):
rsock, wsock = socket.socketpair()
rsock.setblocking(False)

pipeobj = io.open(wsock.detach(), 'wb', 1024)
pipeobj = open(wsock.detach(), 'wb', 1024)

proto = MyWritePipeProto(loop=self.loop)
connect = self.loop.connect_write_pipe(lambda: proto, pipeobj)
Expand All @@ -207,7 +206,7 @@ def test_write_pty(self):
master, slave = os.openpty()
os.set_blocking(master, False)

slave_write_obj = io.open(slave, 'wb', 0)
slave_write_obj = open(slave, 'wb', 0)

proto = MyWritePipeProto(loop=self.loop)
connect = self.loop.connect_write_pipe(lambda: proto, slave_write_obj)
Expand Down Expand Up @@ -250,7 +249,7 @@ def reader(data):

def test_write_buffer_full(self):
rpipe, wpipe = os.pipe()
pipeobj = io.open(wpipe, 'wb', 1024)
pipeobj = open(wpipe, 'wb', 1024)

proto = MyWritePipeProto(loop=self.loop)
connect = self.loop.connect_write_pipe(lambda: proto, pipeobj)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def test():
stdout=subprocess.PIPE)

pid = proc.pid
expected_result = '{}\n'.format(pid).encode()
expected_result = f'{pid}\n'.encode()

out, err = await proc.communicate()
self.assertEqual(out, expected_result)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_process_spawning.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def spawn_process():
t.start()
t.join(timeout=10.0)
if t.is_alive():
raise Exception('process freeze detected at {}'
.format(iteration))
raise Exception(f'process freeze detected at {iteration}'
)

return True

Expand Down
3 changes: 1 addition & 2 deletions tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ def handler_hup():

def test_signals_invalid_signal(self):
with self.assertRaisesRegex(RuntimeError,
'sig {} cannot be caught'.format(
signal.SIGKILL)):
f'sig {signal.SIGKILL} cannot be caught'):

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

Expand Down
10 changes: 4 additions & 6 deletions tests/test_sourcecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ def test_flake8(self):
subprocess.run(
[sys.executable, '-m', 'flake8', '--config', config_path],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
cwd=os.path.join(edgepath, subdir))
except subprocess.CalledProcessError as ex:
output = ex.stdout.decode()
output += '\n'
output += ex.stderr.decode()
raise AssertionError(
'flake8 validation failed: {}\n{}'.format(ex, output)
f'flake8 validation failed: {ex}\n{output}'
) from None

def test_mypy(self):
Expand All @@ -59,14 +58,13 @@ def test_mypy(self):
'uvloop'
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
cwd=edgepath
)
except subprocess.CalledProcessError as ex:
output = ex.stdout.decode()
output += '\n'
output += ex.stderr.decode()
raise AssertionError(
'mypy validation failed: {}\n{}'.format(ex, output)
f'mypy validation failed: {ex}\n{output}'
) from None
Loading
Loading