else:
return None
- def fetchmany(self, size: int = 0) -> Sequence[Row]:
+ def fetchmany(self, size: int = 0) -> List[Row]:
if not size:
size = self.arraysize
with self._conn.lock:
self._pos += len(recs)
return recs
- def fetchall(self) -> Sequence[Row]:
+ def fetchall(self) -> List[Row]:
with self._conn.lock:
recs = self._conn.wait(self._helper._fetch_gen(self, None))
self._pos += len(recs)
else:
return None
- async def fetchmany(self, size: int = 0) -> Sequence[Row]:
+ async def fetchmany(self, size: int = 0) -> List[Row]:
if not size:
size = self.arraysize
async with self._conn.lock:
self._pos += len(recs)
return recs
- async def fetchall(self) -> Sequence[Row]:
+ async def fetchall(self) -> List[Row]:
async with self._conn.lock:
recs = await self._conn.wait(self._helper._fetch_gen(self, None))
self._pos += len(recs)
_test_reveal(stmts, type, mypy, tmpdir)
+@pytest.mark.slow
+@pytest.mark.parametrize("method", ["fetchmany", "fetchall"])
+@pytest.mark.parametrize(
+ "curs, type",
+ [
+ (
+ "conn.cursor()",
+ "List[Tuple[Any, ...]]",
+ ),
+ (
+ "conn.cursor(row_factory=rows.dict_row)",
+ "List[Dict[str, Any]]",
+ ),
+ (
+ "conn.cursor(row_factory=thing_row)",
+ "List[Thing]",
+ ),
+ ],
+)
+@pytest.mark.parametrize("server_side", [False, True])
+@pytest.mark.parametrize("conn_class", ["Connection", "AsyncConnection"])
+def test_fetchsome_type(
+ conn_class, server_side, curs, type, method, mypy, tmpdir
+):
+ await_ = "await" if "Async" in conn_class else ""
+ if server_side:
+ curs = curs.replace("(", "(name='foo',", 1)
+ stmts = f"""\
+conn = {await_} psycopg3.{conn_class}.connect()
+curs = {curs}
+obj = {await_} curs.{method}()
+"""
+ _test_reveal(stmts, type, mypy, tmpdir)
+
+
@pytest.fixture(scope="session")
def mypy(tmp_path_factory):
cache_dir = tmp_path_factory.mktemp(basename="mypy_cache")
stmts = "\n".join(f" {line}" for line in stmts.splitlines())
src = f"""\
-from typing import Any, Callable, Dict, NamedTuple, Optional, Sequence, Tuple
+from typing import Any, Callable, Dict, List, NamedTuple, Optional, Sequence, Tuple
import psycopg3
from psycopg3 import rows