Improve pymysql types (#1804)

Add all cursor types and missing show_warnings method in connections

Added show_warnings to connections. No return type specified as this
requires tracing back through missing return types in previous
author's work. This is out of scope for this pull request.

Added SSDictCursor, SSCursor and DictCursorMixin to complete the
Cursors definition.
This commit is contained in:
Daniel Bowman
2018-02-17 01:23:17 +00:00
committed by Jelle Zijlstra
parent 0c2249fbd6
commit 1707d8f466
2 changed files with 20 additions and 6 deletions

View File

@@ -100,10 +100,10 @@ class Connection:
def __enter__(self): ...
def __exit__(self, exc, value, traceback): ...
def query(self, sql): ...
def next_result(self): ...
def next_result(self, unbuffered: bool = ...): ...
def affected_rows(self): ...
def kill(self, thread_id): ...
def ping(self, reconnect=True): ...
def ping(self, reconnect: bool = ...): ...
def set_charset(self, charset): ...
def read_packet(self, packet_type=...): ...
def insert_id(self): ...
@@ -112,6 +112,7 @@ class Connection:
def get_host_info(self): ...
def get_proto_info(self): ...
def get_server_info(self): ...
def show_warnings(self): ...
Warning = ... # type: Any
Error = ... # type: Any
InterfaceError = ... # type: Any

View File

@@ -1,4 +1,4 @@
from typing import Union, Tuple, Any, Dict, Optional, Text
from typing import Union, Tuple, Any, Dict, Optional, Text, Iterator, List
from .connections import Connection
Gen = Union[Tuple[Any, ...], Dict[str, Any]]
@@ -22,12 +22,25 @@ class Cursor:
def executemany(self, query: str, args) -> int: ...
def callproc(self, procname, args=...): ...
def fetchone(self) -> Optional[Gen]: ...
def fetchmany(self, size: Optional[int] = ...) -> Optional[Gen]: ...
def fetchmany(self, size: Optional[int] = ...) -> Union[Optional[Gen], List[Gen]]: ...
def fetchall(self) -> Optional[Tuple[Gen, ...]]: ...
def scroll(self, value, mode=''): ...
def scroll(self, value: int, mode: str = ...): ...
def __iter__(self): ...
class DictCursor(Cursor):
def fetchone(self) -> Optional[Dict[str, Any]]: ...
def fetchmany(self, size=None) -> Optional[Tuple[Dict[str, Any], ...]]: ...
def fetchmany(self, size: Optional[int] = ...) -> Optional[Tuple[Dict[str, Any], ...]]: ...
def fetchall(self) -> Optional[Tuple[Dict[str, Any], ...]]: ...
class DictCursorMixin:
dict_type = ... # type: Any
class SSCursor(Cursor):
# fetchall return type is incompatible with the supertype.
def fetchall(self) -> List[Gen]: ... # type: ignore
def fetchall_unbuffered(self) -> Iterator[Tuple[Gen, ...]]: ...
def __iter__(self) -> Iterator[Tuple[Gen, ...]]: ...
def fetchmany(self, size: Optional[int] = ...) -> List[Gen]: ...
def scroll(self, value: int, mode: str = ...) -> None: ...
class SSDictCursor(DictCursorMixin, SSCursor): ...