From 69ea0ad43fd1b8bac374941a7f729994fec510c9 Mon Sep 17 00:00:00 2001 From: Onno Kortmann Date: Tue, 6 Dec 2016 17:17:21 +0100 Subject: [PATCH] Iteration and fetch* fixes to the sqlite3.Cursor type (#663) - Cursor is an Iterator of Any now, and .__iter__(..) and .__next__(..) have been changed / made explicit to reflect this. - .fetchall(..)/.fetchmany(..)/.fetchone(..) return (lists of) Anys instead of tuples. As per discussion in PR #663, the output of fetching values from the cursor can be customized with a custom assignment to .row_factory. Therefore the correct return type for fetching is Any and not tuple. --- stdlib/2/sqlite3/dbapi2.pyi | 15 ++++++++------- stdlib/3/sqlite3/dbapi2.pyi | 15 ++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/stdlib/2/sqlite3/dbapi2.pyi b/stdlib/2/sqlite3/dbapi2.pyi index 5ef3a3c23..bc26a603f 100644 --- a/stdlib/2/sqlite3/dbapi2.pyi +++ b/stdlib/2/sqlite3/dbapi2.pyi @@ -1,7 +1,7 @@ # Filip Hron # based heavily on Andrey Vlasovskikh's python-skeletons https://github.com/JetBrains/python-skeletons/blob/master/sqlite3.py -from typing import Any, Union, List +from typing import Any, Union, List, Iterator from numbers import Integral from datetime import time, datetime from collections import Iterable @@ -125,7 +125,7 @@ class Connection: def __enter__(self, *args, **kwargs): ... def __exit__(self, *args, **kwargs): ... -class Cursor: +class Cursor(Iterator[Any]): arraysize = ... # type: Any connection = ... # type: Any description = ... # type: Any @@ -140,13 +140,14 @@ class Cursor: def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ... def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]): ... def executescript(self, sql_script: Union[bytes, unicode]) -> Cursor: ... - def fetchall(self) -> List[tuple]: ... - def fetchmany(self, size: Integral = ...) -> List[tuple]: ... - def fetchone(self) -> Union[tuple, None]: ... + def fetchall(self) -> List[Any]: ... + def fetchmany(self, size: Integral = ...) -> List[Any]: ... + def fetchone(self) -> Any: ... def setinputsizes(self, *args, **kwargs): ... def setoutputsize(self, *args, **kwargs): ... - def __iter__(self): ... - def __next__(self): ... + def __iter__(self) -> Cursor: ... + def __next__(self) -> Any: ... + class DataError(DatabaseError): ... diff --git a/stdlib/3/sqlite3/dbapi2.pyi b/stdlib/3/sqlite3/dbapi2.pyi index b75a0f860..7a9101ad9 100644 --- a/stdlib/3/sqlite3/dbapi2.pyi +++ b/stdlib/3/sqlite3/dbapi2.pyi @@ -1,7 +1,7 @@ # Filip Hron # based heavily on Andrey Vlasovskikh's python-skeletons https://github.com/JetBrains/python-skeletons/blob/master/sqlite3.py -from typing import Any, Union, List, AnyStr +from typing import Any, Union, List, AnyStr, Iterator from numbers import Integral from datetime import time, datetime from collections import Iterable @@ -125,7 +125,7 @@ class Connection: def __enter__(self, *args, **kwargs): ... def __exit__(self, *args, **kwargs): ... -class Cursor: +class Cursor(Iterator[Any]): arraysize = ... # type: Any connection = ... # type: Any description = ... # type: Any @@ -140,13 +140,14 @@ class Cursor: def execute(self, sql: str, parameters: Iterable = ...) -> Cursor: ... def executemany(self, sql: str, seq_of_parameters: Iterable[Iterable]): ... def executescript(self, sql_script: Union[bytes, AnyStr]) -> Cursor: ... - def fetchall(self) -> List[tuple]: ... - def fetchmany(self, size: Integral = ...) -> List[tuple]: ... - def fetchone(self) -> Union[tuple, None]: ... + def fetchall(self) -> List[Any]: ... + def fetchmany(self, size: Integral = ...) -> List[Any]: ... + def fetchone(self) -> Any: ... def setinputsizes(self, *args, **kwargs): ... def setoutputsize(self, *args, **kwargs): ... - def __iter__(self): ... - def __next__(self): ... + def __iter__(self) -> Cursor: ... + def __next__(self) -> Any: ... + class DataError(DatabaseError): ...