From 1ad38b06923a1574363135ed9d32443e1fb04131 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 7 May 2025 03:55:12 +0200 Subject: [PATCH] chore: drop redundant brackets --- psycopg/psycopg/_dns.py | 2 +- psycopg/psycopg/dbapi20.py | 2 +- psycopg/psycopg/pq/_debug.py | 2 +- psycopg/psycopg/pq/misc.py | 4 ++-- psycopg/psycopg/types/json.py | 2 +- tests/fix_faker.py | 4 ++-- tools/update_oids.py | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/psycopg/psycopg/_dns.py b/psycopg/psycopg/_dns.py index 4535b73d2..57cc2595f 100644 --- a/psycopg/psycopg/_dns.py +++ b/psycopg/psycopg/_dns.py @@ -141,7 +141,7 @@ class Rfc2782Resolver: host_arg: str = params.get("host", os.environ.get("PGHOST", "")) hosts_in = host_arg.split(",") port_arg: str = str(params.get("port", os.environ.get("PGPORT", ""))) - if len((ports_in := port_arg.split(","))) == 1: + if len(ports_in := port_arg.split(",")) == 1: # If only one port is specified, it applies to all the hosts. ports_in *= len(hosts_in) if len(ports_in) != len(hosts_in): diff --git a/psycopg/psycopg/dbapi20.py b/psycopg/psycopg/dbapi20.py index bffcf327c..79b870f0c 100644 --- a/psycopg/psycopg/dbapi20.py +++ b/psycopg/psycopg/dbapi20.py @@ -72,7 +72,7 @@ class Binary: self.obj = obj def __repr__(self) -> str: - if len((sobj := repr(self.obj))) > 40: + if len(sobj := repr(self.obj)) > 40: sobj = f"{sobj[:35]} ... ({len(sobj)} byteschars)" return f"{self.__class__.__name__}({sobj})" diff --git a/psycopg/psycopg/pq/_debug.py b/psycopg/psycopg/pq/_debug.py index 3efd9a084..4db4c3a9f 100644 --- a/psycopg/psycopg/pq/_debug.py +++ b/psycopg/psycopg/pq/_debug.py @@ -57,7 +57,7 @@ class PGconnDebug: return f"<{cls} {info} at 0x{id(self):x}>" def __getattr__(self, attr: str) -> Any: - if callable((value := getattr(self._pgconn, attr))): + if callable(value := getattr(self._pgconn, attr)): return debugging(value) else: logger.info("PGconn.%s -> %s", attr, value) diff --git a/psycopg/psycopg/pq/misc.py b/psycopg/psycopg/pq/misc.py index 354a30ba9..fc223163f 100644 --- a/psycopg/psycopg/pq/misc.py +++ b/psycopg/psycopg/pq/misc.py @@ -65,7 +65,7 @@ def find_libpq_full_path() -> str | None: import subprocess as sp libdir = sp.check_output(["pg_config", "--libdir"]).strip().decode() - if not os.path.exists((libname := os.path.join(libdir, "libpq.dylib"))): + if not os.path.exists(libname := os.path.join(libdir, "libpq.dylib")): libname = None except Exception as ex: logger.debug("couldn't use pg_config to find libpq: %s", ex) @@ -169,7 +169,7 @@ def connection_summary(pgconn: abc.PGconn) -> str: # before upgrading the ConnStatus enum. status = f"status={pgconn.status} (unkndown)" - if sparts := " ".join(("%s=%s" % part for part in parts)): + if sparts := " ".join("%s=%s" % part for part in parts): sparts = f" ({sparts})" return f"[{status}]{sparts}" diff --git a/psycopg/psycopg/types/json.py b/psycopg/psycopg/types/json.py index f35dd0a8a..d5b6149cc 100644 --- a/psycopg/psycopg/types/json.py +++ b/psycopg/psycopg/types/json.py @@ -119,7 +119,7 @@ class _JsonWrapper: self.dumps = dumps def __repr__(self) -> str: - if len((sobj := repr(self.obj))) > 40: + if len(sobj := repr(self.obj)) > 40: sobj = f"{sobj[:35]} ... ({len(sobj)} chars)" return f"{self.__class__.__name__}({sobj})" diff --git a/tests/fix_faker.py b/tests/fix_faker.py index 05e699ef0..70e1d971c 100644 --- a/tests/fix_faker.py +++ b/tests/fix_faker.py @@ -157,7 +157,7 @@ class Faker: try: cur.execute(self._insert_field_stmt(j), (val,)) except psycopg.DatabaseError as e: - if len((r := repr(val))) > 200: + if len(r := repr(val)) > 200: r = f"{r[:200]}... ({len(r)} chars)" raise Exception( f"value {r!r} at record {i} column0 {j} failed insert: {e}" @@ -181,7 +181,7 @@ class Faker: try: await acur.execute(self._insert_field_stmt(j), (val,)) except psycopg.DatabaseError as e: - if len((r := repr(val))) > 200: + if len(r := repr(val)) > 200: r = f"{r[:200]}... ({len(r)} chars)" raise Exception( f"value {r!r} at record {i} column0 {j} failed insert: {e}" diff --git a/tools/update_oids.py b/tools/update_oids.py index 51d877734..90238d679 100755 --- a/tools/update_oids.py +++ b/tools/update_oids.py @@ -35,7 +35,7 @@ ROOT = Path(__file__).parent.parent def main() -> None: opt = parse_cmdline() - if CrdbConnection.is_crdb((conn := psycopg.connect(opt.dsn, autocommit=True))): + if CrdbConnection.is_crdb(conn := psycopg.connect(opt.dsn, autocommit=True)): conn = CrdbConnection.connect(opt.dsn, autocommit=True) update_crdb_python_oids(conn) else: -- 2.47.3