From 141cb37cdf4f151e2e20c4b11ed86465ab7de79c Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Wed, 21 Apr 2021 09:59:39 +0200 Subject: [PATCH] Avoid repeating the default row_factory in Connection methods We set the default row_factory argument value to None in connect() methods and use row_factory class attribute when unspecified, thus avoiding repetition of the 'tuple_row' value. --- psycopg3/psycopg3/connection.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/psycopg3/psycopg3/connection.py b/psycopg3/psycopg3/connection.py index 204c460b9..a5b4ad6ba 100644 --- a/psycopg3/psycopg3/connection.py +++ b/psycopg3/psycopg3/connection.py @@ -344,7 +344,7 @@ class BaseConnection(AdaptContext): conninfo: str = "", *, autocommit: bool = False, - row_factory: RowFactory[Any], + row_factory: Optional[RowFactory[Any]] = None, **kwargs: Any, ) -> PQGenConn[ConnectionType]: """Generator to connect to the database and create a new instance.""" @@ -352,6 +352,8 @@ class BaseConnection(AdaptContext): pgconn = yield from connect(conninfo) conn = cls(pgconn) conn._autocommit = autocommit + if row_factory is None: + row_factory = cls.row_factory conn.row_factory = row_factory return conn @@ -443,7 +445,7 @@ class Connection(BaseConnection): conninfo: str = "", *, autocommit: bool = False, - row_factory: RowFactory[Any] = tuple_row, + row_factory: Optional[RowFactory[Any]] = None, **kwargs: Any, ) -> "Connection": """ @@ -634,7 +636,7 @@ class AsyncConnection(BaseConnection): conninfo: str = "", *, autocommit: bool = False, - row_factory: RowFactory[Any] = tuple_row, + row_factory: Optional[RowFactory[Any]] = None, **kwargs: Any, ) -> "AsyncConnection": return await cls._wait_conn( -- 2.47.3