From 9660f6c1999671b8a9956f30c5c7659b66da9643 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Tue, 4 Jun 2024 09:40:30 +0200 Subject: [PATCH] refactor: use set literals As suggested by pyupgrade --py38-plus. --- psycopg/psycopg/types/array.py | 2 +- tests/_test_transaction.py | 4 ++-- tests/pool/test_pool.py | 6 +++--- tests/pool/test_pool_async.py | 6 +++--- tests/pool/test_pool_common.py | 4 ++-- tests/pool/test_pool_common_async.py | 4 ++-- tools/async_to_sync.py | 4 +--- tools/bump_version.py | 2 +- 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/psycopg/psycopg/types/array.py b/psycopg/psycopg/types/array.py index 59a09ab54..78f3eaeff 100644 --- a/psycopg/psycopg/types/array.py +++ b/psycopg/psycopg/types/array.py @@ -63,7 +63,7 @@ class BaseListDumper(RecursiveDumper): # More than one type in the list. It might be still good, as long # as they dump with the same oid (e.g. IPv4Network, IPv6Network). dumpers = [self._tx.get_dumper(item, format) for item in types.values()] - oids = set(d.oid for d in dumpers) + oids = {d.oid for d in dumpers} if len(oids) == 1: t, v = types.popitem() else: diff --git a/tests/_test_transaction.py b/tests/_test_transaction.py index 005e48cca..29e7ad70d 100644 --- a/tests/_test_transaction.py +++ b/tests/_test_transaction.py @@ -37,14 +37,14 @@ def inserted(conn): sql = "SELECT * FROM test_table" if isinstance(conn, psycopg.Connection): rows = conn.cursor().execute(sql).fetchall() - return set(v for (v,) in rows) + return {v for (v,) in rows} else: async def f(): cur = conn.cursor() await cur.execute(sql) rows = await cur.fetchall() - return set(v for (v,) in rows) + return {v for (v,) in rows} return f() diff --git a/tests/pool/test_pool.py b/tests/pool/test_pool.py index d5946f2d4..a3e991d1f 100644 --- a/tests/pool/test_pool.py +++ b/tests/pool/test_pool.py @@ -637,7 +637,7 @@ def test_uniform_use(dsn): counts[id(conn)] += 1 assert len(counts) == 4 - assert set(counts.values()) == set([2]) + assert set(counts.values()) == {2} @pytest.mark.slow @@ -712,7 +712,7 @@ def test_check(dsn, caplog): pid = conn.info.backend_pid p.wait(1.0) - pids = set((conn.info.backend_pid for conn in p._pool)) + pids = {conn.info.backend_pid for conn in p._pool} assert pid in pids conn.close() @@ -720,7 +720,7 @@ def test_check(dsn, caplog): p.check() assert len(caplog.records) == 1 p.wait(1.0) - pids2 = set((conn.info.backend_pid for conn in p._pool)) + pids2 = {conn.info.backend_pid for conn in p._pool} assert len(pids & pids2) == 3 assert pid not in pids2 diff --git a/tests/pool/test_pool_async.py b/tests/pool/test_pool_async.py index 160d7119d..bdcedff49 100644 --- a/tests/pool/test_pool_async.py +++ b/tests/pool/test_pool_async.py @@ -640,7 +640,7 @@ async def test_uniform_use(dsn): counts[id(conn)] += 1 assert len(counts) == 4 - assert set(counts.values()) == set([2]) + assert set(counts.values()) == {2} @pytest.mark.slow @@ -714,7 +714,7 @@ async def test_check(dsn, caplog): pid = conn.info.backend_pid await p.wait(1.0) - pids = set(conn.info.backend_pid for conn in p._pool) + pids = {conn.info.backend_pid for conn in p._pool} assert pid in pids await conn.close() @@ -722,7 +722,7 @@ async def test_check(dsn, caplog): await p.check() assert len(caplog.records) == 1 await p.wait(1.0) - pids2 = set(conn.info.backend_pid for conn in p._pool) + pids2 = {conn.info.backend_pid for conn in p._pool} assert len(pids & pids2) == 3 assert pid not in pids2 diff --git a/tests/pool/test_pool_common.py b/tests/pool/test_pool_common.py index 60ef84b89..1f2230cf0 100644 --- a/tests/pool/test_pool_common.py +++ b/tests/pool/test_pool_common.py @@ -182,7 +182,7 @@ def test_queue(pool_cls, dsn): for got, want in zip(times, want_times): assert got == pytest.approx(want, 0.2), times - assert len(set((r[2] for r in results))) == 2, results + assert len({r[2] for r in results}) == 2, results @pytest.mark.slow @@ -272,7 +272,7 @@ def test_dead_client(pool_cls, dsn): gather(*ts) sleep(0.2) - assert set(results) == set([0, 1, 3, 4]) + assert set(results) == {0, 1, 3, 4} if pool_cls is pool.ConnectionPool: assert len(p._pool) == 2 # no connection was lost diff --git a/tests/pool/test_pool_common_async.py b/tests/pool/test_pool_common_async.py index 01cc957a9..4ee23270c 100644 --- a/tests/pool/test_pool_common_async.py +++ b/tests/pool/test_pool_common_async.py @@ -192,7 +192,7 @@ async def test_queue(pool_cls, dsn): for got, want in zip(times, want_times): assert got == pytest.approx(want, 0.2), times - assert len(set(r[2] for r in results)) == 2, results + assert len({r[2] for r in results}) == 2, results @pytest.mark.slow @@ -283,7 +283,7 @@ async def test_dead_client(pool_cls, dsn): await gather(*ts) await asleep(0.2) - assert set(results) == set([0, 1, 3, 4]) + assert set(results) == {0, 1, 3, 4} if pool_cls is pool.AsyncConnectionPool: assert len(p._pool) == 2 # no connection was lost diff --git a/tools/async_to_sync.py b/tools/async_to_sync.py index 41d88fa5b..ba6fd94be 100755 --- a/tools/async_to_sync.py +++ b/tools/async_to_sync.py @@ -144,9 +144,7 @@ def check(outputs: list[str]) -> int: if not maybe_conv: logger.error("no file to check? Maybe this script bitrot?") return 1 - unk_conv = sorted( - set(maybe_conv) - set(fn.replace("_async", "") for fn in ALL_INPUTS) - ) + unk_conv = sorted(set(maybe_conv) - {fn.replace("_async", "") for fn in ALL_INPUTS}) if unk_conv: logger.error( "files converted by %s but not included in ALL_INPUTS: %s", diff --git a/tools/bump_version.py b/tools/bump_version.py index dd371d7ba..65b6e0220 100755 --- a/tools/bump_version.py +++ b/tools/bump_version.py @@ -84,7 +84,7 @@ class Bumper: @cached_property def current_version(self) -> Version: - versions = set(self._parse_version_from_file(f) for f in self.package.ini_files) + versions = {self._parse_version_from_file(f) for f in self.package.ini_files} if len(versions) > 1: raise ValueError( f"inconsistent versions ({', '.join(map(str, sorted(versions)))})" -- 2.47.2