From: Daniele Varrazzo Date: Fri, 16 Jul 2021 15:03:53 +0000 (+0200) Subject: Remove format param from cursor constructor X-Git-Tag: 3.0.dev2~52 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2a8351afd810ac0a6c099cbae64c5009e3157ca2;p=thirdparty%2Fpsycopg.git Remove format param from cursor constructor --- diff --git a/psycopg/psycopg/connection.py b/psycopg/psycopg/connection.py index 64a158d49..9f8f08988 100644 --- a/psycopg/psycopg/connection.py +++ b/psycopg/psycopg/connection.py @@ -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, diff --git a/psycopg/psycopg/cursor.py b/psycopg/psycopg/cursor.py index 4e1946524..c9c1fae25 100644 --- a/psycopg/psycopg/cursor.py +++ b/psycopg/psycopg/cursor.py @@ -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 diff --git a/psycopg/psycopg/server_cursor.py b/psycopg/psycopg/server_cursor.py index 2367c6803..636a8aeb0 100644 --- a/psycopg/psycopg/server_cursor.py +++ b/psycopg/psycopg/server_cursor.py @@ -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