from psycopg import Cursor
class DictRowFactory:
- def __init__(self, cursor: Cursor[dict[str, Any]]):
+ def __init__(self, cursor: Cursor[Any]):
self.fields = [c.name for c in cursor.description]
def __call__(self, values: Sequence[Any]) -> dict[str, Any]:
.. code:: python
- def dict_row_factory(cursor: Cursor[dict[str, Any]]) -> RowMaker[dict[str, Any]]:
+ def dict_row_factory(cursor: Cursor[Any]) -> RowMaker[dict[str, Any]]:
fields = [c.name for c in cursor.description]
def make_row(values: Sequence[Any]) -> dict[str, Any]:
from .cursor import BaseCursor, Cursor
from .cursor_async import AsyncCursor
-T = TypeVar("T")
+T = TypeVar("T", covariant=True)
# Row factories
-Row = TypeVar("Row")
-Row_co = TypeVar("Row_co", covariant=True)
+Row = TypeVar("Row", covariant=True)
-class RowMaker(Protocol[Row_co]):
+class RowMaker(Protocol[Row]):
"""
Callable protocol taking a sequence of value and returning an object.
Typically, `!RowMaker` functions are returned by `RowFactory`.
"""
- def __call__(self, __values: Sequence[Any]) -> Row_co:
+ def __call__(self, __values: Sequence[Any]) -> Row:
...
use the values to create a dictionary for each record.
"""
- def __call__(self, __cursor: "Cursor[Row]") -> RowMaker[Row]:
+ def __call__(self, __cursor: "Cursor[Any]") -> RowMaker[Row]:
...
Like `RowFactory`, taking an async cursor as argument.
"""
- def __call__(self, __cursor: "AsyncCursor[Row]") -> RowMaker[Row]:
+ def __call__(self, __cursor: "AsyncCursor[Any]") -> RowMaker[Row]:
...
Like `RowFactory`, taking either type of cursor as argument.
"""
- def __call__(self, __cursor: "BaseCursor[Any, Row]") -> RowMaker[Row]:
+ def __call__(self, __cursor: "BaseCursor[Any, Any]") -> RowMaker[Row]:
...
"""
-def tuple_row(cursor: "BaseCursor[Any, TupleRow]") -> "RowMaker[TupleRow]":
+def tuple_row(cursor: "BaseCursor[Any, Any]") -> "RowMaker[TupleRow]":
r"""Row factory to represent rows as simple tuples.
This is the default factory, used when `~psycopg.Connection.connect()` or
return tuple
-def dict_row(cursor: "BaseCursor[Any, DictRow]") -> "RowMaker[DictRow]":
+def dict_row(cursor: "BaseCursor[Any, Any]") -> "RowMaker[DictRow]":
"""Row factory to represent rows as dictionaries.
The dictionary keys are taken from the column names of the returned columns.
def namedtuple_row(
- cursor: "BaseCursor[Any, NamedTuple]",
+ cursor: "BaseCursor[Any, Any]",
) -> "RowMaker[NamedTuple]":
"""Row factory to represent rows as `~collections.namedtuple`.
:rtype: `!Callable[[Cursor],` `RowMaker`\[~T]]
"""
- def class_row_(cur: "BaseCursor[Any, T]") -> "RowMaker[T]":
+ def class_row_(cur: "BaseCursor[Any, Any]") -> "RowMaker[T]":
desc = cur.description
if desc is None:
return no_result