From: Denis Laxalde Date: Wed, 21 Apr 2021 07:59:39 +0000 (+0200) Subject: Avoid repeating the default row_factory in Connection methods X-Git-Tag: 3.0.dev0~63^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=141cb37cdf4f151e2e20c4b11ed86465ab7de79c;p=thirdparty%2Fpsycopg.git 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. --- 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(