]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Remove format param from cursor constructor
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 16 Jul 2021 15:03:53 +0000 (17:03 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 23 Jul 2021 14:38:27 +0000 (16:38 +0200)
psycopg/psycopg/connection.py
psycopg/psycopg/cursor.py
psycopg/psycopg/server_cursor.py

index 64a158d49c2ef821425dd0e0aca6747296d8f0db..9f8f08988a10699097be8957eb8ff056df1f6ba4 100644 (file)
@@ -561,15 +561,19 @@ class Connection(BaseConnection[Row]):
         """
         Return a new cursor to send commands and queries to the connection.
         """
-        format = Format.BINARY if binary else Format.TEXT
         if not row_factory:
             row_factory = self.row_factory
+
+        cur: Union[Cursor[Any], ServerCursor[Any]]
         if name:
-            return ServerCursor(
-                self, name=name, format=format, row_factory=row_factory
-            )
+            cur = ServerCursor(self, name=name, row_factory=row_factory)
         else:
-            return Cursor(self, format=format, row_factory=row_factory)
+            cur = Cursor(self, row_factory=row_factory)
+
+        if binary:
+            cur.format = Format.BINARY
+
+        return cur
 
     def execute(
         self,
@@ -772,15 +776,19 @@ class AsyncConnection(BaseConnection[Row]):
         """
         Return a new `AsyncCursor` to send commands and queries to the connection.
         """
-        format = Format.BINARY if binary else Format.TEXT
         if not row_factory:
             row_factory = self.row_factory
+
+        cur: Union[AsyncCursor[Any], AsyncServerCursor[Any]]
         if name:
-            return AsyncServerCursor(
-                self, name=name, format=format, row_factory=row_factory
-            )
+            cur = AsyncServerCursor(self, name=name, row_factory=row_factory)
         else:
-            return AsyncCursor(self, format=format, row_factory=row_factory)
+            cur = AsyncCursor(self, row_factory=row_factory)
+
+        if binary:
+            cur.format = Format.BINARY
+
+        return cur
 
     async def execute(
         self,
index 4e1946524122943be375cfc1ddae90f7d6ac907d..c9c1fae25238b490ca91f0ebfe6e7897e03e18f2 100644 (file)
@@ -58,11 +58,10 @@ class BaseCursor(Generic[ConnectionType, Row]):
         self,
         connection: ConnectionType,
         *,
-        format: Format = Format.TEXT,
         row_factory: RowFactory[Row],
     ):
         self._conn = connection
-        self.format = format
+        self.format = Format.TEXT
         self._adapters = adapt.AdaptersMap(connection.adapters)
         self._row_factory = row_factory
         self.arraysize = 1
index 2367c68035bd79539d06f62aa0d919c1e1d5bcf8..636a8aeb097278f22a232327aab21729f217ed25 100644 (file)
@@ -176,10 +176,9 @@ class ServerCursor(BaseCursor["Connection[Any]", Row]):
         connection: "Connection[Any]",
         name: str,
         *,
-        format: pq.Format = pq.Format.TEXT,
         row_factory: RowFactory[Row],
     ):
-        super().__init__(connection, format=format, row_factory=row_factory)
+        super().__init__(connection, row_factory=row_factory)
         self._helper: ServerCursorHelper["Connection[Any]", Row]
         self._helper = ServerCursorHelper(name)
         self.itersize: int = DEFAULT_ITERSIZE
@@ -297,10 +296,9 @@ class AsyncServerCursor(BaseCursor["AsyncConnection[Any]", Row]):
         connection: "AsyncConnection[Any]",
         name: str,
         *,
-        format: pq.Format = pq.Format.TEXT,
         row_factory: RowFactory[Row],
     ):
-        super().__init__(connection, format=format, row_factory=row_factory)
+        super().__init__(connection, row_factory=row_factory)
         self._helper: ServerCursorHelper["AsyncConnection[Any]", Row]
         self._helper = ServerCursorHelper(name)
         self.itersize: int = DEFAULT_ITERSIZE