From: Daniele Varrazzo Date: Sun, 4 May 2025 16:44:29 +0000 (+0200) Subject: refactor: auto-generate sync server cursor from async X-Git-Tag: 3.2.8~21^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=326e14f40aab389f73dde2c095bf1a8a3b46d3b6;p=thirdparty%2Fpsycopg.git refactor: auto-generate sync server cursor from async --- diff --git a/.flake8 b/.flake8 index 79e029388..ed086adf0 100644 --- a/.flake8 +++ b/.flake8 @@ -12,6 +12,7 @@ per-file-ignores = psycopg/psycopg/errors.py: E125, E128, E302 # Allow concatenated string literals from async_to_sync + psycopg/psycopg/_server_cursor.py: E501 psycopg_pool/psycopg_pool/pool.py: E501 # Pytest's importorskip() getting in the way diff --git a/psycopg/psycopg/_server_cursor.py b/psycopg/psycopg/_server_cursor.py index 86d0b87c8..3b27d1fc7 100644 --- a/psycopg/psycopg/_server_cursor.py +++ b/psycopg/psycopg/_server_cursor.py @@ -1,5 +1,8 @@ +# WARNING: this file is auto-generated by 'async_to_sync.py' +# from the original file '_server_cursor_async.py' +# DO NOT CHANGE! Change the original file instead. """ -psycopg server-side cursor objects. +psycopg server-side cursor (sync). """ # Copyright (C) 2020 The Psycopg Team @@ -63,8 +66,7 @@ class ServerCursor(ServerCursorMixin["Connection[Any]", Row], Cursor[Row]): def __del__(self) -> None: if not self.closed: warn( - f"the server-side cursor {self} was deleted while still open." - " Please use 'with' or '.close()' to close the cursor properly", + f"the server-side cursor {self} was deleted while still open. Please use 'with' or '.close()' to close the cursor properly", ResourceWarning, ) diff --git a/psycopg/psycopg/_server_cursor_async.py b/psycopg/psycopg/_server_cursor_async.py index a64168e3b..7ac9baff8 100644 --- a/psycopg/psycopg/_server_cursor_async.py +++ b/psycopg/psycopg/_server_cursor_async.py @@ -1,5 +1,5 @@ """ -psycopg async server-side cursor objects. +psycopg server-side cursor (async). """ # Copyright (C) 2020 The Psycopg Team @@ -71,6 +71,9 @@ class AsyncServerCursor( ) async def close(self) -> None: + """ + Close the current cursor and free associated resources. + """ async with self._conn.lock: if self.closed: return @@ -86,6 +89,9 @@ class AsyncServerCursor( binary: bool | None = None, **kwargs: Any, ) -> Self: + """ + Open a cursor to execute a query to the database. + """ if kwargs: raise TypeError(f"keyword not supported: {list(kwargs)[0]}") if self._pgconn.pipeline_status: @@ -104,6 +110,7 @@ class AsyncServerCursor( async def executemany( self, query: Query, params_seq: Iterable[Params], *, returning: bool = True ) -> None: + """Method not implemented for server-side cursors.""" raise e.NotSupportedError("executemany not supported on server-side cursors") async def fetchone(self) -> Row | None: diff --git a/tools/async_to_sync.py b/tools/async_to_sync.py index b3dc18695..24d8918cc 100755 --- a/tools/async_to_sync.py +++ b/tools/async_to_sync.py @@ -34,6 +34,7 @@ ALL_INPUTS = """ psycopg/psycopg/_copy_async.py psycopg/psycopg/connection_async.py psycopg/psycopg/cursor_async.py + psycopg/psycopg/_server_cursor_async.py psycopg_pool/psycopg_pool/null_pool_async.py psycopg_pool/psycopg_pool/pool_async.py psycopg_pool/psycopg_pool/sched_async.py @@ -299,6 +300,7 @@ class RenameAsyncToSync(ast.NodeTransformer): # type: ignore "__aexit__": "__exit__", "__aiter__": "__iter__", "_copy_async": "_copy", + "_server_cursor_async": "_server_cursor", "aclose": "close", "aclosing": "closing", "acommands": "commands",