From 06416219667b0286ec7001d93f4e36a2837aa8ed Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Sat, 7 Jan 2023 08:31:41 +0100 Subject: [PATCH] refactor: introduce BaseCursor._set_results() Similar to _set_results_from_pipeline(), this applies to the non-pipeline case and reduce code repetition. --- psycopg/psycopg/cursor.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 8379c589a..30dcb9774 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -201,8 +201,7 @@ class BaseCursor(Generic[ConnectionType, Row]): else: assert results is not None self._check_results(results) - self._results = results - self._select_current_result(0) + self._set_results(results) self._last_query = query @@ -413,8 +412,7 @@ class BaseCursor(Generic[ConnectionType, Row]): raise e.ProgrammingError("COPY cannot be mixed with other operations") self._check_copy_result(results[0]) - self._results = results - self._select_current_result(0) + self._set_results(results) def _execute_send( self, @@ -529,6 +527,10 @@ class BaseCursor(Generic[ConnectionType, Row]): self._make_row = self._make_row_maker() + def _set_results(self, results: List["PGresult"]) -> None: + self._results = results + self._select_current_result(0) + def _set_results_from_pipeline(self, results: List["PGresult"]) -> None: self._check_results(results) first_batch = not self._results -- 2.47.3