]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Avoid repeating the default row_factory in Connection methods
authorDenis Laxalde <denis.laxalde@dalibo.com>
Wed, 21 Apr 2021 07:59:39 +0000 (09:59 +0200)
committerDenis Laxalde <denis.laxalde@dalibo.com>
Mon, 26 Apr 2021 14:00:59 +0000 (16:00 +0200)
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

index 204c460b927ff5f4929e8be7190a20d97b6b7548..a5b4ad6baa743d3ba42f51a4f3f150f389e8d526 100644 (file)
@@ -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(