From 05c0865b9c33de4df92f6b91c419c174de238f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= Date: Tue, 18 Jun 2024 19:06:16 +0000 Subject: [PATCH 1/2] really drop python<=3.7 support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Filter all code over `pyupgrade --py38-plus`. Signed-off-by: Tomasz Kłoczko --- docs/conf.py | 2 +- examples/bench/echoclient.py | 2 +- examples/bench/echoserver.py | 2 +- examples/bench/rlserver.py | 2 +- setup.py | 4 ++-- tests/test_aiohttp.py | 2 +- tests/test_context.py | 8 ++++---- tests/test_dns.py | 2 +- tests/test_fs_event.py | 2 +- tests/test_pipes.py | 12 ++++++------ tests/test_process.py | 2 +- tests/test_process_spawning.py | 2 +- tests/test_sourcecode.py | 10 ++++------ tests/test_tcp.py | 2 +- tests/test_unix.py | 2 +- uvloop/__init__.py | 2 +- uvloop/_testbase.py | 8 ++++---- 17 files changed, 32 insertions(+), 34 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 5884d0ff..530c1cc1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,7 @@ version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'uvloop', '_version.py') -with open(version_file, 'r') as f: +with open(version_file) as f: for line in f: if line.startswith('__version__ ='): _, _, version = line.partition('=') diff --git a/examples/bench/echoclient.py b/examples/bench/echoclient.py index 711b2f11..dbca1d26 100644 --- a/examples/bench/echoclient.py +++ b/examples/bench/echoclient.py @@ -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 diff --git a/examples/bench/echoserver.py b/examples/bench/echoserver.py index 906ca85a..b08116d6 100644 --- a/examples/bench/echoserver.py +++ b/examples/bench/echoserver.py @@ -138,7 +138,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: diff --git a/examples/bench/rlserver.py b/examples/bench/rlserver.py index 90b84bee..3092f28c 100644 --- a/examples/bench/rlserver.py +++ b/examples/bench/rlserver.py @@ -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: diff --git a/setup.py b/setup.py index ba15af50..575a9d2b 100644 --- a/setup.py +++ b/setup.py @@ -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(): @@ -176,7 +176,7 @@ def build_libuv(self): cmd, cwd=LIBUV_BUILD_DIR, env=env, check=True) - j_flag = '-j{}'.format(os.cpu_count() or 1) + j_flag = f'-j{os.cpu_count() or 1}' c_flag = "CFLAGS={}".format(env['CFLAGS']) subprocess.run( ['make', j_flag, c_flag], diff --git a/tests/test_aiohttp.py b/tests/test_aiohttp.py index 514d0177..6ab639c3 100644 --- a/tests/test_aiohttp.py +++ b/tests/test_aiohttp.py @@ -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" diff --git a/tests/test_context.py b/tests/test_context.py index 03733756..16a79a2a 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -202,16 +202,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) diff --git a/tests/test_dns.py b/tests/test_dns.py index f61b1e8a..4d45ec0d 100644 --- a/tests/test_dns.py +++ b/tests/test_dns.py @@ -214,7 +214,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(): diff --git a/tests/test_fs_event.py b/tests/test_fs_event.py index 743589b5..0d79e321 100644 --- a/tests/test_fs_event.py +++ b/tests/test_fs_event.py @@ -86,7 +86,7 @@ async def run(write_task): with tempfile.TemporaryDirectory() as td_name: self.dname = td_name - f = open(os.path.join(td_name, self.changed_name), 'wt') + f = open(os.path.join(td_name, self.changed_name), 'w') f.write('hello!') f.close() h = self.loop._monitor_fs(td_name, self.event_cb) diff --git a/tests/test_pipes.py b/tests/test_pipes.py index c2b8a016..6f24e5e8 100644 --- a/tests/test_pipes.py +++ b/tests/test_pipes.py @@ -74,7 +74,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( @@ -106,7 +106,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( @@ -142,7 +142,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) @@ -185,7 +185,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) @@ -207,7 +207,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) @@ -250,7 +250,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) diff --git a/tests/test_process.py b/tests/test_process.py index bfcbba17..329b2264 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -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) diff --git a/tests/test_process_spawning.py b/tests/test_process_spawning.py index 71fe914d..a29d7c8d 100644 --- a/tests/test_process_spawning.py +++ b/tests/test_process_spawning.py @@ -56,7 +56,7 @@ async def spawn_external_process(loop, event): BufferType = ctypes.c_char * (BUFFER_LENGTH - 1) def run_echo(popen, fread, pclose): - fd = popen('echo test'.encode('ASCII'), 'r'.encode('ASCII')) + fd = popen(b'echo test', b'r') try: while True: buffer = BufferType() diff --git a/tests/test_sourcecode.py b/tests/test_sourcecode.py index 370ec6ff..51cf51a0 100644 --- a/tests/test_sourcecode.py +++ b/tests/test_sourcecode.py @@ -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): @@ -59,8 +58,7 @@ def test_mypy(self): 'uvloop' ], check=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + capture_output=True, cwd=edgepath ) except subprocess.CalledProcessError as ex: @@ -68,5 +66,5 @@ def test_mypy(self): output += '\n' output += ex.stderr.decode() raise AssertionError( - 'mypy validation failed: {}\n{}'.format(ex, output) + f'mypy validation failed: {ex}\n{output}' ) from None diff --git a/tests/test_tcp.py b/tests/test_tcp.py index 812e62b8..8f861941 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -2806,7 +2806,7 @@ async def test(): except AssertionError as e: self.assertEqual(str(e), 'ResourceWarning not triggered') else: - self.fail('Unexpected ResourceWarning: {}'.format(cm.warning)) + self.fail(f'Unexpected ResourceWarning: {cm.warning}') def test_handshake_timeout_handler_leak(self): if self.implementation == 'asyncio': diff --git a/tests/test_unix.py b/tests/test_unix.py index 8adedeef..b9cbd672 100644 --- a/tests/test_unix.py +++ b/tests/test_unix.py @@ -166,7 +166,7 @@ async def start_server_sock(start_server): def test_create_unix_server_2(self): with tempfile.TemporaryDirectory() as td: sock_name = os.path.join(td, 'sock') - with open(sock_name, 'wt') as f: + with open(sock_name, 'w') as f: f.write('x') with self.assertRaisesRegex( diff --git a/uvloop/__init__.py b/uvloop/__init__.py index 9bb6592b..07364527 100644 --- a/uvloop/__init__.py +++ b/uvloop/__init__.py @@ -71,7 +71,7 @@ async def wrapper(): if not __asyncio.iscoroutine(main): raise ValueError( - "a coroutine was expected, got {!r}".format(main) + f"a coroutine was expected, got {main!r}" ) loop = loop_factory() diff --git a/uvloop/_testbase.py b/uvloop/_testbase.py index c4a7595b..490e1385 100644 --- a/uvloop/_testbase.py +++ b/uvloop/_testbase.py @@ -141,14 +141,14 @@ def tearDown(self): handle_name=h_name): self.assertEqual( h_cnt, 0, - 'alive {} after test'.format(h_name)) + f'alive {h_name} after test') for h_name, h_cnt in self.loop._debug_handles_total.items(): with self.subTest('Total/closed handles', handle_name=h_name): self.assertEqual( h_cnt, self.loop._debug_handles_closed[h_name], - 'total != closed for {}'.format(h_name)) + f'total != closed for {h_name}') asyncio.set_event_loop(None) asyncio.set_event_loop_policy(None) @@ -259,7 +259,7 @@ def find_free_port(start_from=50000): with sock: try: sock.bind(('', port)) - except socket.error: + except OSError: continue else: return port @@ -386,7 +386,7 @@ def __getattr__(self, name): return getattr(self.__sock, name) def __repr__(self): - return '<{} {!r}>'.format(type(self).__name__, self.__sock) + return f'<{type(self).__name__} {self.__sock!r}>' class SocketThread(threading.Thread): From 665329836e63226df383049607812e610fa8a4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82oczko?= Date: Tue, 18 Jun 2024 19:11:04 +0000 Subject: [PATCH 2/2] remove cede duplicated in pyprojest.tomil decalaration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "requires-python = '>=3.8.0'" in pyproject.toml is enough. Signed-off-by: Tomasz Kłoczko --- setup.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/setup.py b/setup.py index 575a9d2b..1377ef11 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,5 @@ import sys -vi = sys.version_info -if vi < (3, 8): - raise RuntimeError('uvloop requires Python 3.8 or greater') - if sys.platform in ('win32', 'cygwin', 'cli'): raise RuntimeError('uvloop does not support Windows at the moment')