From: Daniele Varrazzo Date: Sun, 2 Jan 2022 18:47:37 +0000 (+0100) Subject: Rename a couple of internal cursor methods for clarity X-Git-Tag: pool-3.1~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7b6dde57c5435c18f4633226eb7a16a6c4b7d4c;p=thirdparty%2Fpsycopg.git Rename a couple of internal cursor methods for clarity --- diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 10c0d9420..c12cf1f12 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -157,7 +157,7 @@ class BaseCursor(Generic[ConnectionType, Row]): methods `!fetch*()` will operate on. """ if self._iresult < len(self._results) - 1: - self._set_result(self._iresult + 1) + self._set_current_result(self._iresult + 1) return True else: return None @@ -199,7 +199,7 @@ class BaseCursor(Generic[ConnectionType, Row]): ) self._check_results(results) self._results = results - self._set_result(0) + self._set_current_result(0) self._last_query = query for cmd in self._conn._prepared.get_maintenance_commands(): @@ -227,7 +227,7 @@ class BaseCursor(Generic[ConnectionType, Row]): nrows += res.command_tuples or 0 if self._results: - self._set_result(0) + self._set_current_result(0) # Override rowcount for the first result. Calls to nextset() will change # it to the value of that result only, but we hope nobody will notice. @@ -429,7 +429,9 @@ class BaseCursor(Generic[ConnectionType, Row]): f" {ExecStatus(result.status).name}" ) - def _set_result(self, i: int, format: Optional[Format] = None) -> None: + def _set_current_result( + self, i: int, format: Optional[Format] = None + ) -> None: """ Select one of the results in the cursor as the active one. """ @@ -461,7 +463,7 @@ class BaseCursor(Generic[ConnectionType, Row]): name, pgq.params, param_formats=pgq.formats, result_format=fmt ) - def _check_result(self) -> None: + def _check_result_for_fetch(self) -> None: if self.closed: raise e.InterfaceError("the cursor is closed") res = self.pgresult @@ -488,7 +490,7 @@ class BaseCursor(Generic[ConnectionType, Row]): ) def _scroll(self, value: int, mode: str) -> None: - self._check_result() + self._check_result_for_fetch() assert self.pgresult if mode == "relative": newpos = self._pos + value @@ -612,7 +614,7 @@ class Cursor(BaseCursor["Connection[Any]", Row]): :rtype: Optional[Row], with Row defined by `row_factory` """ - self._check_result() + self._check_result_for_fetch() record = self._tx.load_row(self._pos, self._make_row) if record is not None: self._pos += 1 @@ -626,7 +628,7 @@ class Cursor(BaseCursor["Connection[Any]", Row]): :rtype: Sequence[Row], with Row defined by `row_factory` """ - self._check_result() + self._check_result_for_fetch() assert self.pgresult if not size: @@ -645,7 +647,7 @@ class Cursor(BaseCursor["Connection[Any]", Row]): :rtype: Sequence[Row], with Row defined by `row_factory` """ - self._check_result() + self._check_result_for_fetch() assert self.pgresult records = self._tx.load_rows( self._pos, self.pgresult.ntuples, self._make_row @@ -654,7 +656,7 @@ class Cursor(BaseCursor["Connection[Any]", Row]): return records def __iter__(self) -> Iterator[Row]: - self._check_result() + self._check_result_for_fetch() def load(pos: int) -> Optional[Row]: return self._tx.load_row(pos, self._make_row) diff --git a/psycopg/psycopg/cursor_async.py b/psycopg/psycopg/cursor_async.py index 1e34bef65..cd3f04915 100644 --- a/psycopg/psycopg/cursor_async.py +++ b/psycopg/psycopg/cursor_async.py @@ -109,14 +109,14 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): first = False async def fetchone(self) -> Optional[Row]: - self._check_result() + self._check_result_for_fetch() rv = self._tx.load_row(self._pos, self._make_row) if rv is not None: self._pos += 1 return rv async def fetchmany(self, size: int = 0) -> List[Row]: - self._check_result() + self._check_result_for_fetch() assert self.pgresult if not size: @@ -130,7 +130,7 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): return records async def fetchall(self) -> List[Row]: - self._check_result() + self._check_result_for_fetch() assert self.pgresult records = self._tx.load_rows( self._pos, self.pgresult.ntuples, self._make_row @@ -139,7 +139,7 @@ class AsyncCursor(BaseCursor["AsyncConnection[Any]", Row]): return records async def __aiter__(self) -> AsyncIterator[Row]: - self._check_result() + self._check_result_for_fetch() def load(pos: int) -> Optional[Row]: return self._tx.load_row(pos, self._make_row) diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index f973a7aac..1488b71c8 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -89,7 +89,7 @@ class ServerCursorHelper(Generic[ConnectionType, Row]): results = yield from execute(conn.pgconn) cur._check_results(results) cur._results = results - cur._set_result(0, format=self._format) + cur._set_current_result(0, format=self._format) self.described = True def _close_gen(self, cur: BaseCursor[ConnectionType, Row]) -> PQGen[None]: