From eaa9f3f0d02efda4c8061e880c3a75a11269170f Mon Sep 17 00:00:00 2001 From: Filip Hron Date: Fri, 4 Mar 2016 01:46:51 +0100 Subject: [PATCH] sqlite3 documentation excursion --- stdlib/2.7/sqlite3/dbapi2.pyi | 89 +++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 35 deletions(-) diff --git a/stdlib/2.7/sqlite3/dbapi2.pyi b/stdlib/2.7/sqlite3/dbapi2.pyi index aa423c25f..61b3faf68 100644 --- a/stdlib/2.7/sqlite3/dbapi2.pyi +++ b/stdlib/2.7/sqlite3/dbapi2.pyi @@ -2,14 +2,17 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any +from typing import Any, Union, List +from datetime import time as _time, datetime as _datetime +from collections import Iterable as _Iterable, Callable as _Callable +from sqlite3 import Connection as _Connection, Cursor as _Cursor -paramstyle = ... # type: Any -threadsafety = ... # type: Any -apilevel = ... # type: Any -Date = ... # type: Any -Time = ... # type: Any -Timestamp = ... # type: Any +paramstyle = ... # type: str +threadsafety = ... # type: int +apilevel = ... # type: str +Date = ... # type: type +Time = ... # type: _time +Timestamp = ... # type: _datetime def DateFromTicks(ticks): ... def TimeFromTicks(ticks): ... @@ -61,18 +64,26 @@ converters = ... # type: Any sqlite_version = ... # type: str version = ... # type: str +# TODO: adapt needs to get probed def adapt(obj, protocol, alternate): ... -def complete_statement(sql): ... -def connect(*args, **kwargs): ... -def enable_callback_tracebacks(flag): ... -def enable_shared_cache(do_enable): ... -def register_adapter(type, callable): ... -def register_converter(typename, callable): ... +def complete_statement(sql: str) -> bool: ... +def connect(database: Union[bytes, unicode],\ + timeout: float = ... ,\ + detect_types: int = ...,\ + isolation_level: Union[str, None] = ...,\ + check_same_thread: bool = ...,\ + factory: Union[_Connection, None] = ...,\ + cached_statements: int = ...) -> _Connection: ... +def enable_callback_tracebacks(flag: bool) -> None: ... +def enable_shared_cache(do_enable: int) -> None: ... +def register_adapter(type: type, callable: Any) -> None: ... +# TODO: sqlite3.register_converter.__doc__ specifies callable as unknown +def register_converter(typename: str, callable: bytes) -> None: ... class Cache: - def __init__(self, *args, **kwargs): ... - def display(self, *args, **kwargs): ... - def get(self, *args, **kwargs): ... + def __init__(self, *args, **kwargs) -> None: ... + def display(self, *args, **kwargs) -> None: ... + def get(self, *args, **kwargs) -> None: ... class Connection: DataError = ... # type: Any @@ -91,20 +102,25 @@ class Connection: text_factory = ... # type: Any total_changes = ... # type: Any def __init__(self, *args, **kwargs): ... - def close(self, *args, **kwargs): ... - def commit(self, *args, **kwargs): ... - def create_aggregate(self, *args, **kwargs): ... - def create_collation(self, *args, **kwargs): ... - def create_function(self, *args, **kwargs): ... - def cursor(self, *args, **kwargs): ... - def execute(self, *args, **kwargs): ... - def executemany(self, *args, **kwargs): ... - def executescript(self, *args, **kwargs): ... - def interrupt(self, *args, **kwargs): ... - def iterdump(self, *args, **kwargs): ... + def close(self) -> None: ... + def commit(self) -> None: ... + def create_aggregate(self, name: str, num_params: int, aggregate_class: type) -> None: ... + def create_collation(self, name: str, callable: _Callable) -> None: ... + def create_function(self, name: str, num_params: int, func: _Callable) -> None: ... + def cursor(self, cursorClass= Union[type, None]) -> _Cursor: ... + def execute(self, sql: str, parameters: _Iterable) -> _Cursor: ... + # TODO: please check in executemany() if seq_of_parameters type is possible like this + def executemany(self, sql: str, seq_of_parameters: _Iterable[_Iterable]) -> _Cursor: ... + def executescript(self, sql_script: Union[bytes, unicode]) -> _Cursor: ... + def interrupt(self, *args, **kwargs) -> None: ... + def iterdump(self, *args, **kwargs) -> None: ... def rollback(self, *args, **kwargs): ... - def set_authorizer(self, *args, **kwargs): ... - def set_progress_handler(self, *args, **kwargs): ... + # TODO: set_authorizer(authorzer_callback) + # see https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.set_authorizer + # returns [SQLITE_OK, SQLITE_DENY, SQLITE_IGNORE] so perhaps int + def set_authorizer(self, *args, **kwargs) -> None: ... + # set_progress_handler(handler, n) -> see https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.set_progress_handler + def set_progress_handler(self, *args, **kwargs) -> None: ... def set_trace_callback(self, *args, **kwargs): ... def __call__(self, *args, **kwargs): ... def __enter__(self, *args, **kwargs): ... @@ -117,14 +133,17 @@ class Cursor: lastrowid = ... # type: Any row_factory = ... # type: Any rowcount = ... # type: Any + # TODO: Cursor class accepts exactly 1 argument + # required type is sqlite3.Connection (which is imported as _Connection) + # however, the name of the __init__ variable is unknown def __init__(self, *args, **kwargs): ... def close(self, *args, **kwargs): ... - def execute(self, *args, **kwargs): ... - def executemany(self, *args, **kwargs): ... - def executescript(self, *args, **kwargs): ... - def fetchall(self, *args, **kwargs): ... - def fetchmany(self, *args, **kwargs): ... - def fetchone(self, *args, **kwargs): ... + 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 setinputsizes(self, *args, **kwargs): ... def setoutputsize(self, *args, **kwargs): ... def __iter__(self): ...