From: Daniele Varrazzo Date: Thu, 28 Oct 2021 15:55:37 +0000 (+0200) Subject: refactor: compose DECLARE in the helper common path X-Git-Tag: 3.0.2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d476b238f7232a63335e658fca1edc3ade84d204;p=thirdparty%2Fpsycopg.git refactor: compose DECLARE in the helper common path ...instead of in the separate sync/async branches. --- diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index d936b7b6f..7c2e2e7e9 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -62,7 +62,9 @@ class ServerCursorHelper(Generic[ConnectionType, Row]): params: Optional[Params] = None, ) -> PQGen[None]: """Generator implementing `ServerCursor.execute()`.""" + conn = cur._conn + query = self._make_declare_statement(conn, query) # If the cursor is being reused, the previous one must be closed. if self.described: @@ -153,13 +155,11 @@ class ServerCursorHelper(Generic[ConnectionType, Row]): yield from cur._conn._exec_command(query) def _make_declare_statement( - self, - cur: BaseCursor[ConnectionType, Row], - query: Query, + self, conn: ConnectionType, query: Query ) -> sql.Composable: if isinstance(query, bytes): - query = query.decode(pgconn_encoding(cur._conn.pgconn)) + query = query.decode(pgconn_encoding(conn.pgconn)) if not isinstance(query, sql.Composable): query = sql.SQL(query) @@ -257,7 +257,6 @@ class ServerCursor(Cursor[Row]): if kwargs: raise TypeError(f"keyword not supported: {list(kwargs)[0]}") helper = self._helper - query = helper._make_declare_statement(self, query) if binary is None: helper.format = self.format @@ -378,7 +377,6 @@ class AsyncServerCursor(AsyncCursor[Row]): if kwargs: raise TypeError(f"keyword not supported: {list(kwargs)[0]}") helper = self._helper - query = helper._make_declare_statement(self, query) if binary is None: helper.format = self.format