From: Daniele Varrazzo Date: Wed, 8 Apr 2020 10:10:12 +0000 (+1200) Subject: fetchone() made async on async cursor X-Git-Tag: 3.0.dev0~589 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b8592b40b89cbe85456d74ddcc2c398afff7e79d;p=thirdparty%2Fpsycopg.git fetchone() made async on async cursor --- diff --git a/psycopg3/cursor.py b/psycopg3/cursor.py index 6c809db73..f878daf7f 100644 --- a/psycopg3/cursor.py +++ b/psycopg3/cursor.py @@ -131,12 +131,6 @@ class BaseCursor: else: return None - def fetchone(self) -> Optional[Sequence[Any]]: - rv = self._cast_row(self._pos) - if rv is not None: - self._pos += 1 - return rv - def _cast_row(self, n: int) -> Optional[Tuple[Any, ...]]: res = self.pgresult if res is None: @@ -164,6 +158,12 @@ class Cursor(BaseCursor): self._execute_results(results) return self + def fetchone(self) -> Optional[Sequence[Any]]: + rv = self._cast_row(self._pos) + if rv is not None: + self._pos += 1 + return rv + class AsyncCursor(BaseCursor): conn: "AsyncConnection" @@ -180,6 +180,12 @@ class AsyncCursor(BaseCursor): self._execute_results(results) return self + async def fetchone(self) -> Optional[Sequence[Any]]: + rv = self._cast_row(self._pos) + if rv is not None: + self._pos += 1 + return rv + class NamedCursorMixin: pass diff --git a/tests/test_async_connection.py b/tests/test_async_connection.py index df1116566..d92555523 100644 --- a/tests/test_async_connection.py +++ b/tests/test_async_connection.py @@ -41,7 +41,7 @@ def test_rollback(loop, pq, aconn): def test_get_encoding(aconn, loop): cur = aconn.cursor() loop.run_until_complete(cur.execute("show client_encoding")) - (enc,) = cur.fetchone() + (enc,) = loop.run_until_complete(cur.fetchone()) assert enc == aconn.encoding @@ -59,7 +59,7 @@ def test_set_encoding(aconn, loop): assert aconn.encoding == newenc cur = aconn.cursor() loop.run_until_complete(cur.execute("show client_encoding")) - (enc,) = cur.fetchone() + (enc,) = loop.run_until_complete(cur.fetchone()) assert enc == newenc