]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Return type of fetch methods improved
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 8 Jan 2021 01:24:33 +0000 (02:24 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 8 Jan 2021 01:32:29 +0000 (02:32 +0100)
psycopg3/psycopg3/_transform.py
psycopg3/psycopg3/cursor.py
psycopg3/psycopg3/proto.py
psycopg3/psycopg3/types/composite.py
psycopg3/psycopg3/types/range.py
psycopg3_c/psycopg3_c/_psycopg3.pyi
psycopg3_c/psycopg3_c/_psycopg3/transform.pyx

index 1cdea90d06a30f12521150d231883abe5a3477b0..1f792f5634e2333f2369186e3ff7d61eed44274c 100644 (file)
@@ -131,7 +131,7 @@ class Transformer(AdaptContext):
             f"cannot adapt type {cls.__name__} to format {Format(format).name}"
         )
 
-    def load_rows(self, row0: int, row1: int) -> Sequence[Tuple[Any, ...]]:
+    def load_rows(self, row0: int, row1: int) -> List[Tuple[Any, ...]]:
         res = self._pgresult
         if not res:
             raise e.InterfaceError("result not set")
index d3ac286089a3a9071cd062c9408abedbd6544c63..9c029cf8df3f176c7c4cf0b671b989718ae4a7bc 100644 (file)
@@ -446,7 +446,7 @@ class Cursor(BaseCursor["Connection"]):
             self._pos += 1
         return record
 
-    def fetchmany(self, size: int = 0) -> List[Sequence[Any]]:
+    def fetchmany(self, size: int = 0) -> Sequence[Sequence[Any]]:
         """
         Return the next *size* records from the current recordset.
 
@@ -461,9 +461,9 @@ class Cursor(BaseCursor["Connection"]):
             self._pos, min(self._pos + size, self.pgresult.ntuples)
         )
         self._pos += len(records)
-        return records  # type: ignore[return-value]
+        return records
 
-    def fetchall(self) -> List[Sequence[Any]]:
+    def fetchall(self) -> Sequence[Sequence[Any]]:
         """
         Return all the remaining records from the current recordset.
         """
@@ -471,7 +471,7 @@ class Cursor(BaseCursor["Connection"]):
         assert self.pgresult
         records = self._transformer.load_rows(self._pos, self.pgresult.ntuples)
         self._pos += self.pgresult.ntuples
-        return records  # type: ignore[return-value]
+        return records
 
     def __iter__(self) -> Iterator[Sequence[Any]]:
         self._check_result()
@@ -541,7 +541,7 @@ class AsyncCursor(BaseCursor["AsyncConnection"]):
             self._pos += 1
         return rv
 
-    async def fetchmany(self, size: int = 0) -> List[Sequence[Any]]:
+    async def fetchmany(self, size: int = 0) -> Sequence[Sequence[Any]]:
         self._check_result()
         assert self.pgresult
 
@@ -551,14 +551,14 @@ class AsyncCursor(BaseCursor["AsyncConnection"]):
             self._pos, min(self._pos + size, self.pgresult.ntuples)
         )
         self._pos += len(records)
-        return records  # type: ignore[return-value]
+        return records
 
-    async def fetchall(self) -> List[Sequence[Any]]:
+    async def fetchall(self) -> Sequence[Sequence[Any]]:
         self._check_result()
         assert self.pgresult
         records = self._transformer.load_rows(self._pos, self.pgresult.ntuples)
         self._pos += self.pgresult.ntuples
-        return records  # type: ignore[return-value]
+        return records
 
     async def __aiter__(self) -> AsyncIterator[Sequence[Any]]:
         self._check_result()
index f0a5a4c3e1dd59e8511e440b99f16145a9b3e412..fbaa6eea4a60dfa5de19acef24fdb96f593cb872 100644 (file)
@@ -99,7 +99,7 @@ class Transformer(Protocol):
     def get_dumper(self, obj: Any, format: Format) -> "Dumper":
         ...
 
-    def load_rows(self, row0: int, row1: int) -> Sequence[Tuple[Any, ...]]:
+    def load_rows(self, row0: int, row1: int) -> List[Tuple[Any, ...]]:
         ...
 
     def load_row(self, row: int) -> Optional[Tuple[Any, ...]]:
index 5ad3bee4ee1d61a2a1078cce9775cc747bf046cf..0aabb4653ebd4bc3eb4dfba8eae26ebb5124820e 100644 (file)
@@ -105,7 +105,7 @@ class CompositeInfo(TypeInfo):
             )
 
     @classmethod
-    def _from_records(cls, recs: List[Any]) -> Optional["CompositeInfo"]:
+    def _from_records(cls, recs: Sequence[Any]) -> Optional["CompositeInfo"]:
         if not recs:
             return None
         if len(recs) > 1:
index d204d44e6220ddddeee2f7150c60225c22e711d1..e8102d22bca6913a2ae348d57e04c008ed922cee 100644 (file)
@@ -5,7 +5,7 @@ Support for range types adaptation.
 # Copyright (C) 2020 The Psycopg Team
 
 import re
-from typing import Any, Dict, Generic, List, Optional, TypeVar, Type, Union
+from typing import Any, Dict, Generic, Optional, Sequence, TypeVar, Type, Union
 from typing import cast, TYPE_CHECKING
 from decimal import Decimal
 from datetime import date, datetime
@@ -413,7 +413,7 @@ class RangeInfo(TypeInfo):
             )
 
     @classmethod
-    def _from_records(cls, recs: List[Any]) -> Optional["RangeInfo"]:
+    def _from_records(cls, recs: Sequence[Any]) -> Optional["RangeInfo"]:
         if not recs:
             return None
         if len(recs) > 1:
index 9e24e0b831c55afd279d2aee24682be7ba9c3d4f..b1043a528963304fd88314e408559f12b1821ea5 100644 (file)
@@ -32,7 +32,7 @@ class Transformer(proto.AdaptContext):
         self, params: Sequence[Any], formats: Sequence[Format]
     ) -> Tuple[List[Any], Tuple[int, ...]]: ...
     def get_dumper(self, obj: Any, format: Format) -> Dumper: ...
-    def load_rows(self, row0: int, row1: int) -> Sequence[Tuple[Any, ...]]: ...
+    def load_rows(self, row0: int, row1: int) -> List[Tuple[Any, ...]]: ...
     def load_row(self, row: int) -> Optional[Tuple[Any, ...]]: ...
     def load_sequence(
         self, record: Sequence[Optional[bytes]]
index 4b9c62e439599c5085972149aba611dcb4d744a2..8d9ea6ff3a177d2580d9e335f3ebb7aed7a7070c 100644 (file)
@@ -222,7 +222,7 @@ cdef class Transformer:
 
         return ps, ts
 
-    def load_rows(self, int row0, int row1) -> Sequence[Tuple[Any, ...]]:
+    def load_rows(self, int row0, int row1) -> List[Tuple[Any, ...]]:
         if self._pgresult is None:
             raise e.InterfaceError("result not set")