]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Further negotiation for good row types docs 47/head
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 30 Apr 2021 14:42:09 +0000 (16:42 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 30 Apr 2021 15:10:06 +0000 (17:10 +0200)
Improvements can be made, however I would rather merge this branch to
master and improve the whole docs.

docs/advanced/rows.rst
psycopg3/psycopg3/rows.py

index f75dc2024cc741b1180815338d836a5ac6183913..f130b60974a24d7cfb5962b4deaf41afbc303d6e 100644 (file)
@@ -16,13 +16,22 @@ protocol) is a callable that accepts a `Cursor` object and returns another
 callable (formally the `~psycopg3.rows.RowMaker` protocol) accepting a
 `values` tuple and returning a row in the desired form.
 
-.. autoclass:: psycopg3.rows.RowMaker
+.. autoclass:: psycopg3.rows.RowMaker()
 
-   .. automethod:: __call__
+   .. method:: __call__(values: Sequence[Any]) -> Row
 
-.. autoclass:: psycopg3.rows.RowFactory
+        Convert a sequence of values from the database to a finished object.
+
+
+.. autoclass:: psycopg3.rows.RowFactory()
+
+   .. method:: __call__(cursor: AnyCursor[Row]) -> RowMaker[Row]
+
+        Inspect the result on a cursor and return a `RowMaker` to convert rows.
+
+        `!AnyCursor` may be either a `~psycopg3.Cursor` or an
+        `~psycopg3.AsyncCursor`.
 
-   .. automethod:: __call__
 
 `~RowFactory` objects can be implemented as a class, for instance:
 
@@ -75,13 +84,13 @@ The module `psycopg3.rows` provides the implementation for a few row factories:
 
 .. currentmodule:: psycopg3.rows
 
-.. autofunction:: tuple_row
+.. autofunction:: tuple_row(cursor: AnyCursor[TupleRow])
 .. autodata:: TupleRow
 
-.. autofunction:: dict_row
+.. autofunction:: dict_row(cursor: AnyCursor[DictRow])
 .. autodata:: DictRow
 
-.. autofunction:: namedtuple_row
+.. autofunction:: namedtuple_row(cursor: AnyCursor[NamedTuple])
 
 
 Use with a static analyzer
index f295e008549e2f6f841ddd11924c728742fef5c6..4aafe3500df646a32dbfdda08a3ef3c746aeaff8 100644 (file)
@@ -31,13 +31,10 @@ class RowMaker(Protocol[Row_co]):
     program would like to receive: by default (`tuple_row()`) it is a simple
     tuple, but it may be any type of object.
 
-    Typically, `~RowMaker` functions are returned by `RowFactory`.
+    Typically, `!RowMaker` functions are returned by `RowFactory`.
     """
 
     def __call__(self, __values: Sequence[Any]) -> Row_co:
-        """
-        Convert a sequence of values from the database to a finished object.
-        """
         ...
 
 
@@ -56,9 +53,6 @@ class RowFactory(Protocol[Row]):
     """
 
     def __call__(self, __cursor: "AnyCursor[Row]") -> RowMaker[Row]:
-        """
-        Inspect the result on a cursor and return a `RowMaker` to convert rows.
-        """
         ...
 
 
@@ -75,6 +69,7 @@ def tuple_row(
 
     This is the default factory.
 
+    :param cursor: The cursor where the rows are read.
     :rtype: `RowMaker`\ [`TupleRow`]
     """
     # Implementation detail: make sure this is the tuple type itself, not an
@@ -99,6 +94,7 @@ def dict_row(
     Note that this is not compatible with the DBAPI, which expects the records
     to be sequences.
 
+    :param cursor: The cursor where the rows are read.
     :rtype: `RowMaker`\ [`DictRow`]
     """
 
@@ -117,6 +113,7 @@ def namedtuple_row(
 ) -> Callable[[Sequence[Any]], NamedTuple]:
     r"""Row factory to represent rows as `~collections.namedtuple`.
 
+    :param cursor: The cursor where the rows are read.
     :rtype: `RowMaker`\ [`NamedTuple`]
     """