]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
refactor: auto-generate sync server cursor from async
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 4 May 2025 16:44:29 +0000 (18:44 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 4 May 2025 17:36:28 +0000 (19:36 +0200)
.flake8
psycopg/psycopg/_server_cursor.py
psycopg/psycopg/_server_cursor_async.py
tools/async_to_sync.py

diff --git a/.flake8 b/.flake8
index 79e029388048c5ca75725c6bd2ad3353bacc472f..ed086adf0efc6701ea866b825acfcc8f79a90e06 100644 (file)
--- 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
index 86d0b87c8a1a435f1ab45430bb20a98d903c4ad6..3b27d1fc736b556625021b2e118dea47536a0daf 100644 (file)
@@ -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,
             )
 
index a64168e3bff68f936fdf58b9616efbea2bae3b79..7ac9baff88146e4b30602402ae2fc4c681dcc321 100644 (file)
@@ -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:
index b3dc18695f6a6217854db4a06bf77be9af9e6d17..24d8918cc3b62895036547f6ad971f6e07e79b69 100755 (executable)
@@ -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",