From 355f92e7242f430188d2c7879c05c1276d2de491 Mon Sep 17 00:00:00 2001 From: Maxim Masiutin Date: Tue, 20 Apr 2021 16:46:14 +0300 Subject: [PATCH] Stubs (.pyi) for type definition for connection and cursor objects --- stubs/mysql/__init__.pyi | 0 stubs/mysql/connector/__init__.pyi | 47 ++++++ stubs/mysql/connector/abstracts.pyi | 192 ++++++++++++++++++++++ stubs/mysql/connector/connection.pyi | 116 +++++++++++++ stubs/mysql/connector/connection_cext.pyi | 108 ++++++++++++ 5 files changed, 463 insertions(+) create mode 100644 stubs/mysql/__init__.pyi create mode 100644 stubs/mysql/connector/__init__.pyi create mode 100644 stubs/mysql/connector/abstracts.pyi create mode 100644 stubs/mysql/connector/connection.pyi create mode 100644 stubs/mysql/connector/connection_cext.pyi diff --git a/stubs/mysql/__init__.pyi b/stubs/mysql/__init__.pyi new file mode 100644 index 0000000..e69de29 diff --git a/stubs/mysql/connector/__init__.pyi b/stubs/mysql/connector/__init__.pyi new file mode 100644 index 0000000..f2f1f40 --- /dev/null +++ b/stubs/mysql/connector/__init__.pyi @@ -0,0 +1,47 @@ +from .abstracts import MySQLConnectionAbstract as MySQLConnectionAbstract +from .connection import MySQLConnection as MySQLConnection +from .connection_cext import CMySQLConnection as CMySQLConnection +from .constants import ( + CharacterSet as CharacterSet, + ClientFlag as ClientFlag, + FieldFlag as FieldFlag, + FieldType as FieldType, + RefreshOption as RefreshOption, +) +from .dbapi import ( + BINARY as BINARY, + Binary as Binary, + DATETIME as DATETIME, + Date as Date, + DateFromTicks as DateFromTicks, + NUMBER as NUMBER, + ROWID as ROWID, + STRING as STRING, + Time as Time, + TimeFromTicks as TimeFromTicks, + Timestamp as Timestamp, + TimestampFromTicks as TimestampFromTicks, + apilevel as apilevel, + paramstyle as paramstyle, + threadsafety as threadsafety, +) +from .errors import ( + DataError as DataError, + DatabaseError as DatabaseError, + Error as Error, + IntegrityError as IntegrityError, + InterfaceError as InterfaceError, + InternalError as InternalError, + NotSupportedError as NotSupportedError, + OperationalError as OperationalError, + ProgrammingError as ProgrammingError, + Warning as Warning, + custom_error_exception as custom_error_exception, +) +from typing import Any + +HAVE_CEXT: bool + +def connect(*args: Any, **kwargs: Any) -> MySQLConnectionAbstract: ... + +Connect = connect diff --git a/stubs/mysql/connector/abstracts.pyi b/stubs/mysql/connector/abstracts.pyi new file mode 100644 index 0000000..e6820f7 --- /dev/null +++ b/stubs/mysql/connector/abstracts.pyi @@ -0,0 +1,192 @@ +import abc +from . import errors as errors +from .catch23 import BYTE_TYPES as BYTE_TYPES, make_abc as make_abc +from .constants import ( + CharacterSet as CharacterSet, + ClientFlag as ClientFlag, + DEFAULT_CONFIGURATION as DEFAULT_CONFIGURATION, +) +from .conversion import MySQLConverterBase as MySQLConverterBase +from .optionfiles import MySQLOptionsParser as MySQLOptionsParser +from abc import abstractmethod +from typing import Any, Optional + +class MySQLConnectionAbstract(metaclass=abc.ABCMeta): + converter: Any = ... + def __init__(self, **kwargs: Any) -> None: ... + @property + def user(self): ... + @property + def server_host(self): ... + @property + def server_port(self): ... + @property + def unix_socket(self): ... + @property + @abc.abstractmethod + def database(self) -> MySQLConnectionAbstract: ... + @database.setter + def database(self, value: Any) -> MySQLConnectionAbstract: ... + @property + def can_consume_results(self): ... + def config(self, **kwargs: Any) -> None: ... + def get_server_version(self): ... + def get_server_info(self): ... + @property + @abc.abstractmethod + def in_transaction(self) -> Any: ... + def set_client_flags(self, flags: Any): ... + def isset_client_flag(self, flag: Any): ... + @property + def time_zone(self): ... + @time_zone.setter + def time_zone(self, value: Any) -> None: ... + @property + def sql_mode(self): ... + @sql_mode.setter + def sql_mode(self, value: Any) -> None: ... + @abstractmethod + def info_query(self, query: Any) -> MySQLCursorAbstract: ... + def set_login( + self, username: Optional[Any] = ..., password: Optional[Any] = ... + ) -> None: ... + def set_unicode(self, value: bool = ...) -> None: ... + @property + def autocommit(self): ... + @autocommit.setter + def autocommit(self, value: Any) -> None: ... + @property + def get_warnings(self): ... + @get_warnings.setter + def get_warnings(self, value: Any) -> None: ... + @property + def raise_on_warnings(self): ... + @raise_on_warnings.setter + def raise_on_warnings(self, value: Any) -> None: ... + @property + def unread_result(self) -> bool: ... + @unread_result.setter + def unread_result(self, value: bool): ... + @property + def charset(self): ... + @property + def python_charset(self): ... + def set_charset_collation( + self, charset: Optional[Any] = ..., collation: Optional[Any] = ... + ) -> None: ... + @property + def collation(self): ... + @abstractmethod + def disconnect(self) -> Any: ... + close: Any = ... + def connect(self, **kwargs: Any) -> MySQLConnectionAbstract: ... + def reconnect(self, attempts: int = ..., delay: int = ...) -> None: ... + @abstractmethod + def is_connected(self) -> Any: ... + @abstractmethod + def ping( + self, reconnect: bool = ..., attempts: int = ..., delay: int = ... + ) -> Any: ... + @abstractmethod + def commit(self) -> Any: ... + @abstractmethod + def cursor( + self, + buffered: Optional[Any] = ..., + raw: Optional[Any] = ..., + prepared: Optional[Any] = ..., + cursor_class: Optional[Any] = ..., + dictionary: Optional[Any] = ..., + named_tuple: Optional[Any] = ..., + ) -> MySQLCursorAbstract: ... + @abstractmethod + def rollback(self) -> Any: ... + def start_transaction( + self, + consistent_snapshot: bool = ..., + isolation_level: Optional[Any] = ..., + readonly: Optional[Any] = ..., + ) -> None: ... + def reset_session( + self, + user_variables: Optional[Any] = ..., + session_variables: Optional[Any] = ..., + ) -> None: ... + def set_converter_class(self, convclass: Any) -> None: ... + @abstractmethod + def get_rows( + self, + count: Optional[Any] = ..., + binary: bool = ..., + columns: Optional[Any] = ..., + ) -> Any: ... + def cmd_init_db(self, database: Any) -> None: ... + def cmd_query( + self, + query: Any, + raw: bool = ..., + buffered: bool = ..., + raw_as_string: bool = ..., + ) -> None: ... + def cmd_query_iter(self, statements: Any) -> None: ... + def cmd_refresh(self, options: Any) -> None: ... + def cmd_quit(self) -> None: ... + def cmd_shutdown(self, shutdown_type: Optional[Any] = ...) -> None: ... + def cmd_statistics(self) -> None: ... + def cmd_process_info(self) -> None: ... + def cmd_process_kill(self, mysql_pid: Any) -> None: ... + def cmd_debug(self) -> None: ... + def cmd_ping(self) -> None: ... + def cmd_change_user( + self, + username: str = ..., + password: str = ..., + database: str = ..., + charset: int = ..., + ) -> None: ... + def cmd_stmt_prepare(self, statement: Any) -> None: ... + def cmd_stmt_execute( + self, + statement_id: Any, + data: Any = ..., + parameters: Any = ..., + flags: int = ..., + ) -> None: ... + def cmd_stmt_close(self, statement_id: Any) -> None: ... + def cmd_stmt_send_long_data( + self, statement_id: Any, param_id: Any, data: Any + ) -> None: ... + def cmd_stmt_reset(self, statement_id: Any) -> None: ... + def cmd_reset_connection(self) -> None: ... + +class MySQLCursorAbstract(metaclass=abc.ABCMeta): + arraysize: int = ... + def __init__(self) -> None: ... + @abstractmethod + def callproc(self, procname: Any, args: Any = ...) -> Any: ... + @abstractmethod + def close(self) -> Any: ... + @abstractmethod + def execute(self, operation: Any, params: Any = ..., multi: bool = ...) -> Any: ... + @abstractmethod + def executemany(self, operation: Any, seqparams: Any) -> Any: ... + @abstractmethod + def fetchone(self) -> Any: ... + @abstractmethod + def fetchmany(self, size: int = ...) -> Any: ... + @abstractmethod + def fetchall(self) -> Any: ... + def nextset(self) -> None: ... + def setinputsizes(self, sizes: Any) -> None: ... + def setoutputsize(self, size: Any, column: Optional[Any] = ...) -> None: ... + def reset(self, free: bool = ...) -> None: ... + @property + @abc.abstractmethod + def description(self) -> Any: ... + @property + @abc.abstractmethod + def rowcount(self) -> Any: ... + @property + @abc.abstractmethod + def lastrowid(self) -> Any: ... + def fetchwarnings(self): ... diff --git a/stubs/mysql/connector/connection.pyi b/stubs/mysql/connector/connection.pyi new file mode 100644 index 0000000..816e87c --- /dev/null +++ b/stubs/mysql/connector/connection.pyi @@ -0,0 +1,116 @@ +from . import errors as errors +from .abstracts import ( + MySQLConnectionAbstract as MySQLConnectionAbstract, + MySQLCursorAbstract as MySQLCursorAbstract, +) +from .authentication import get_auth_plugin as get_auth_plugin +from .catch23 import PY2 as PY2, isstr as isstr +from .constants import ( + ClientFlag as ClientFlag, + NET_BUFFER_LENGTH as NET_BUFFER_LENGTH, + ServerCmd as ServerCmd, + ServerFlag as ServerFlag, + ShutdownType as ShutdownType, + flag_is_set as flag_is_set, +) +from .conversion import MySQLConverter as MySQLConverter +from .cursor import ( + CursorBase as CursorBase, + MySQLCursor as MySQLCursor, + MySQLCursorBuffered as MySQLCursorBuffered, + MySQLCursorBufferedDict as MySQLCursorBufferedDict, + MySQLCursorBufferedNamedTuple as MySQLCursorBufferedNamedTuple, + MySQLCursorBufferedRaw as MySQLCursorBufferedRaw, + MySQLCursorDict as MySQLCursorDict, + MySQLCursorNamedTuple as MySQLCursorNamedTuple, + MySQLCursorPrepared as MySQLCursorPrepared, + MySQLCursorRaw as MySQLCursorRaw, +) +from .network import ( + MySQLTCPSocket as MySQLTCPSocket, + MySQLUnixSocket as MySQLUnixSocket, +) +from .protocol import MySQLProtocol as MySQLProtocol +from .utils import int4store as int4store +from typing import Any, Optional + +class MySQLConnection(MySQLConnectionAbstract): + def __init__(self, *args: Any, **kwargs: Any) -> None: ... + def shutdown(self) -> None: ... + def close(self) -> None: ... + disconnect: Any = ... + @property + def in_transaction(self): ... + def get_row(self, binary: bool = ..., columns: Optional[Any] = ...): ... + @property + def get_rows( + self, + count: Optional[Any] = ..., + binary: Optional[bool] = ..., + columns: Optional[Any] = ..., + ): ... + def consume_results(self) -> None: ... + def cmd_init_db(self, database: Any): ... + def cmd_query( + self, + query: Any, + raw: bool = ..., + buffered: bool = ..., + raw_as_string: bool = ..., + ): ... + def cmd_query_iter(self, statements: Any) -> None: ... + def cmd_refresh(self, options: Any): ... + def cmd_quit(self): ... + def cmd_shutdown(self, shutdown_type: Optional[Any] = ...): ... + def cmd_statistics(self): ... + def cmd_process_kill(self, mysql_pid: Any): ... + def cmd_debug(self): ... + def cmd_ping(self): ... + def cmd_change_user( + self, + username: str = ..., + password: str = ..., + database: str = ..., + charset: int = ..., + ): ... + @property + def database(self) -> MySQLConnection: ... + @database.setter + def database(self, value: Any) -> MySQLConnection: ... + def is_connected(self): ... + def reset_session( + self, + user_variables: Optional[Any] = ..., + session_variables: Optional[Any] = ..., + ) -> None: ... + def reconnect(self, attempts: int = ..., delay: int = ...) -> None: ... + def ping( + self, reconnect: bool = ..., attempts: int = ..., delay: int = ... + ) -> None: ... + @property + def connection_id(self): ... + def cursor( + self, + buffered: Optional[Any] = ..., + raw: Optional[Any] = ..., + prepared: Optional[Any] = ..., + cursor_class: Optional[Any] = ..., + dictionary: Optional[Any] = ..., + named_tuple: Optional[Any] = ..., + ) -> MySQLCursorAbstract: ... + def commit(self) -> None: ... + def rollback(self) -> None: ... + def info_query(self, query: Any): ... + def cmd_stmt_prepare(self, statement: Any): ... + def cmd_stmt_execute( + self, + statement_id: Any, + data: Any = ..., + parameters: Any = ..., + flags: int = ..., + ): ... + def cmd_stmt_close(self, statement_id: Any) -> None: ... + def cmd_stmt_send_long_data(self, statement_id: Any, param_id: Any, data: Any): ... + def cmd_stmt_reset(self, statement_id: Any) -> None: ... + def cmd_reset_connection(self) -> None: ... + def handle_unread_result(self) -> None: ... diff --git a/stubs/mysql/connector/connection_cext.pyi b/stubs/mysql/connector/connection_cext.pyi new file mode 100644 index 0000000..7b04fba --- /dev/null +++ b/stubs/mysql/connector/connection_cext.pyi @@ -0,0 +1,108 @@ +from . import errors as errors +from .abstracts import ( + MySQLConnectionAbstract as MySQLConnectionAbstract, + MySQLCursorAbstract as MySQLCursorAbstract, +) +from .catch23 import INT_TYPES as INT_TYPES +from .constants import ( + CharacterSet as CharacterSet, + ClientFlag as ClientFlag, + FieldFlag as FieldFlag, + ServerFlag as ServerFlag, + ShutdownType as ShutdownType, +) +from .cursor_cext import ( + CMySQLCursor as CMySQLCursor, + CMySQLCursorBuffered as CMySQLCursorBuffered, + CMySQLCursorBufferedDict as CMySQLCursorBufferedDict, + CMySQLCursorBufferedNamedTuple as CMySQLCursorBufferedNamedTuple, + CMySQLCursorBufferedRaw as CMySQLCursorBufferedRaw, + CMySQLCursorDict as CMySQLCursorDict, + CMySQLCursorNamedTuple as CMySQLCursorNamedTuple, + CMySQLCursorPrepared as CMySQLCursorPrepared, + CMySQLCursorRaw as CMySQLCursorRaw, +) +from .protocol import MySQLProtocol as MySQLProtocol +from typing import Any, Optional + +HAVE_CMYSQL: bool + +class CMySQLConnection(MySQLConnectionAbstract): + converter: Any = ... + def __init__(self, **kwargs: Any) -> None: ... + def set_unicode(self, value: bool = ...) -> None: ... + @property + def autocommit(self): ... + @autocommit.setter + def autocommit(self, value: Any) -> None: ... + @property + def database(self) -> CMySQLConnection: ... + @database.setter + def database(self, value: Any) -> CMySQLConnection: ... + @property + def in_transaction(self): ... + def close(self) -> None: ... + disconnect: Any = ... + def is_connected(self): ... + def ping( + self, reconnect: bool = ..., attempts: int = ..., delay: int = ... + ) -> None: ... + def set_character_set_name(self, charset: Any) -> None: ... + def info_query(self, query: Any): ... + @property + def connection_id(self): ... + def get_rows( + self, + count: Optional[Any] = ..., + binary: bool = ..., + columns: Optional[Any] = ..., + ): ... + def get_row(self, binary: bool = ..., columns: Optional[Any] = ...): ... + def next_result(self): ... + def free_result(self) -> None: ... + def commit(self) -> None: ... + def rollback(self) -> None: ... + def cmd_init_db(self, database: Any) -> None: ... + def fetch_eof_columns(self): ... + def fetch_eof_status(self): ... + def cmd_query( + self, + query: Any, + raw: bool = ..., + buffered: bool = ..., + raw_as_string: bool = ..., + ): ... + def cursor( + self, + buffered: Optional[Any] = ..., + raw: Optional[Any] = ..., + prepared: Optional[Any] = ..., + cursor_class: Optional[Any] = ..., + dictionary: Optional[Any] = ..., + named_tuple: Optional[Any] = ..., + ) -> MySQLCursorAbstract: ... + @property + def num_rows(self): ... + @property + def warning_count(self): ... + @property + def result_set_available(self): ... + @property + def unread_result(self) -> bool: ... + @property + def more_results(self): ... + def prepare_for_mysql(self, params: Any): ... + def consume_results(self) -> None: ... + def cmd_change_user( + self, + username: str = ..., + password: str = ..., + database: str = ..., + charset: int = ..., + ) -> None: ... + def cmd_refresh(self, options: Any): ... + def cmd_quit(self) -> None: ... + def cmd_shutdown(self, shutdown_type: Optional[Any] = ...) -> None: ... + def cmd_statistics(self): ... + def cmd_process_kill(self, mysql_pid: Any) -> None: ... + def handle_unread_result(self) -> None: ...