From bad4efc46ded1b59c2acb4fecb9df6f097c708fd Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 30 Oct 2021 18:30:17 +0200 Subject: [PATCH] Harmless refactoring to server-side cursors It's cool that mypy finds the common base of the two expressions in the ternary operator. --- psycopg/psycopg/server_cursor.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index 2f4ee7ba4..f89f470fb 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -45,15 +45,10 @@ class ServerCursorHelper(Generic[ConnectionType, Row]): self._format = pq.Format.TEXT def _repr(self, cur: BaseCursor[ConnectionType, Row]) -> str: - cls = f"{cur.__class__.__module__}.{cur.__class__.__qualname__}" - info = pq.misc.connection_summary(cur._conn.pgconn) - if cur.closed: - status = "closed" - elif not cur.pgresult: - status = "no result" - else: - status = pq.ExecStatus(cur.pgresult.status).name - return f"<{cls} {self.name!r} [{status}] {info} at 0x{id(cur):x}>" + # Insert the name as the second word + parts = parts = BaseCursor.__repr__(cur).split(None, 1) + parts.insert(1, f"{self.name!r}") + return " ".join(parts) def _declare_gen( self, @@ -133,13 +128,9 @@ class ServerCursorHelper(Generic[ConnectionType, Row]): yield from cur._start_query() yield from self._describe_gen(cur) - if num is not None: - howmuch: sql.Composable = sql.Literal(num) - else: - howmuch = sql.SQL("ALL") - query = sql.SQL("FETCH FORWARD {} FROM {}").format( - howmuch, sql.Identifier(self.name) + sql.SQL("ALL") if num is None else sql.Literal(num), + sql.Identifier(self.name), ) res = yield from cur._conn._exec_command( query, result_format=self._format -- 2.47.2