From 45ad2a8ad86a7ddf5abaeeda54e8d39d6f2cf78a Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 21:03:00 +0300 Subject: [PATCH 01/12] fix returning correct cursor classes --- stubs/PyMySQL/pymysql/__init__.pyi | 9 +++-- stubs/PyMySQL/pymysql/connections.pyi | 53 ++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/stubs/PyMySQL/pymysql/__init__.pyi b/stubs/PyMySQL/pymysql/__init__.pyi index 35532caa8688..a3fc864e63b5 100644 --- a/stubs/PyMySQL/pymysql/__init__.pyi +++ b/stubs/PyMySQL/pymysql/__init__.pyi @@ -1,7 +1,7 @@ import sys from typing import Callable, FrozenSet, Tuple -from .connections import Connection as _Connection +from .connections import Connection as Connection from .constants import FIELD_TYPE as FIELD_TYPE from .converters import escape_dict as escape_dict, escape_sequence as escape_sequence, escape_string as escape_string from .err import ( @@ -50,14 +50,15 @@ if sys.version_info >= (3, 0): else: def Binary(x) -> bytearray: ... -def Connect(*args, **kwargs) -> _Connection: ... def get_client_info() -> str: ... -connect: Callable[..., _Connection] -Connection: Callable[..., _Connection] __version__: str version_info: Tuple[int, int, int, str, int] NULL: str +# pymysql/__init__.py says "Connect = connect = Connection = connections.Connection" +Connect = Connection +connect = Connection + def thread_safe() -> bool: ... def install_as_MySQLdb() -> None: ... diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index 4f8f505d1028..8c426a004e13 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -1,5 +1,5 @@ from socket import socket as _socket -from typing import Any, AnyStr, Mapping, Optional, Tuple, Type +from typing import Any, AnyStr, Mapping, Optional, Tuple, Type, TypeVar, Generic, overload from .charset import charset_by_id as charset_by_id, charset_by_name as charset_by_name from .constants import CLIENT as CLIENT, COMMAND as COMMAND, FIELD_TYPE as FIELD_TYPE, SERVER_STATUS as SERVER_STATUS @@ -11,6 +11,9 @@ DEFAULT_USER: Any DEBUG: Any DEFAULT_CHARSET: Any +_C = TypeVar("_C", bound=Cursor) +_C2 = TypeVar("_C2", bound=Cursor) + def dump_packet(data): ... def pack_int24(n): ... def lenenc_int(i: int) -> bytes: ... @@ -49,7 +52,7 @@ class FieldDescriptorPacket(MysqlPacket): def description(self): ... def get_column_length(self): ... -class Connection: +class Connection(Generic[_C]): ssl: Any host: Any port: Any @@ -71,8 +74,45 @@ class Connection: init_command: Any max_allowed_packet: int server_public_key: bytes + @overload + def __init__( + self: Connection[Cursor], # different between overloads + host: Optional[str] = ..., + user: Optional[Any] = ..., + password: str = ..., + database: Optional[Any] = ..., + port: int = ..., + unix_socket: Optional[Any] = ..., + charset: str = ..., + sql_mode: Optional[Any] = ..., + read_default_file: Optional[Any] = ..., + conv=..., + use_unicode: Optional[bool] = ..., + client_flag: int = ..., + cursorclass: None = ..., # different between overloads + init_command: Optional[Any] = ..., + connect_timeout: Optional[int] = ..., + ssl: Mapping[Any, Any] | None = ..., + read_default_group: Optional[Any] = ..., + compress: Optional[Any] = ..., + named_pipe: Optional[Any] = ..., + autocommit: Optional[bool] = ..., + db: Optional[Any] = ..., + passwd: Optional[Any] = ..., + local_infile: Optional[Any] = ..., + max_allowed_packet: int = ..., + defer_connect: Optional[bool] = ..., + auth_plugin_map: Mapping[Any, Any] | None = ..., + read_timeout: Optional[float] = ..., + write_timeout: Optional[float] = ..., + bind_address: Optional[Any] = ..., + binary_prefix: Optional[bool] = ..., + program_name: Optional[Any] = ..., + server_public_key: Optional[bytes] = ..., + ): ... + @overload def __init__( - self, + self: Connection[_C], # different between overloads host: Optional[str] = ..., user: Optional[Any] = ..., password: str = ..., @@ -85,7 +125,7 @@ class Connection: conv=..., use_unicode: Optional[bool] = ..., client_flag: int = ..., - cursorclass: Optional[Type[Cursor]] = ..., + cursorclass: Type[_C] = ..., # different between overloads init_command: Optional[Any] = ..., connect_timeout: Optional[int] = ..., ssl: Mapping[Any, Any] | None = ..., @@ -121,7 +161,10 @@ class Connection: def escape(self, obj, mapping: Mapping[Any, Any] | None = ...): ... def literal(self, obj): ... def escape_string(self, s: AnyStr) -> AnyStr: ... - def cursor(self, cursor: Optional[Type[Cursor]] = ...) -> Cursor: ... + @overload + def cursor(self, cursor: None = ...) -> _C: ... + @overload + def cursor(self, cursor: Type[_C2]) -> _C2: ... def query(self, sql, unbuffered: bool = ...) -> int: ... def next_result(self, unbuffered: bool = ...) -> int: ... def affected_rows(self): ... From d1acaddf3587eda8aeeecd9084f077de0027f51b Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 21:48:37 +0300 Subject: [PATCH 02/12] fix fetch return types --- stubs/PyMySQL/pymysql/cursors.pyi | 32 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/stubs/PyMySQL/pymysql/cursors.pyi b/stubs/PyMySQL/pymysql/cursors.pyi index b49901950d09..15859c49612e 100644 --- a/stubs/PyMySQL/pymysql/cursors.pyi +++ b/stubs/PyMySQL/pymysql/cursors.pyi @@ -2,7 +2,6 @@ from typing import Any, Dict, Iterable, Iterator, List, Optional, Text, Tuple, T from .connections import Connection -_Gen = Union[Tuple[Any, ...], Dict[Text, Any]] _QueryArgs = Union[Tuple[Any, ...], List[Any], Dict[Text, Any], None] _SelfT = TypeVar("_SelfT") @@ -25,28 +24,27 @@ class Cursor: def execute(self, query: Text, args: _QueryArgs = ...) -> int: ... def executemany(self, query: Text, args: Iterable[_QueryArgs]) -> Optional[int]: ... def callproc(self, procname: Text, args: Iterable[Any] = ...) -> Any: ... - def fetchone(self) -> Optional[_Gen]: ... - def fetchmany(self, size: Optional[int] = ...) -> Union[Optional[_Gen], List[_Gen]]: ... - def fetchall(self) -> Optional[Tuple[_Gen, ...]]: ... def scroll(self, value: int, mode: Text = ...) -> None: ... - def __iter__(self) -> Iterator[_Gen]: ... def __enter__(self: _SelfT) -> _SelfT: ... def __exit__(self, *exc_info: Any) -> None: ... - -class DictCursor(Cursor): - def fetchone(self) -> Optional[Dict[Text, Any]]: ... - def fetchmany(self, size: Optional[int] = ...) -> Optional[Tuple[Dict[Text, Any], ...]]: ... - def fetchall(self) -> Optional[Tuple[Dict[Text, Any], ...]]: ... + # Methods returning result tuples are below. + def fetchone(self) -> Tuple[Any, ...] | None: ... + def fetchmany(self, size: int | None = ...) -> Tuple[Tuple[Any, ...], ...]: ... + def fetchall(self) -> Tuple[Tuple[Any, ...], ...]: ... + def __iter__(self) -> Iterator[Tuple[Any, ...]]: ... class DictCursorMixin: - dict_type: Any + dict_type: Any # TODO: add support if someone needs this + def fetchone(self) -> dict[Text, Any] | None: ... + def fetchmany(self, size: int | None = ...) -> Tuple[dict[Text, Any], ...]: ... + def fetchall(self) -> Tuple[dict[Text, Any], ...]: ... + def __iter__(self) -> Iterator[dict[Text, Any]]: ... class SSCursor(Cursor): - # fetchall return type is incompatible with the supertype. - def fetchall(self) -> List[_Gen]: ... # type: ignore - def fetchall_unbuffered(self) -> Iterator[_Gen]: ... - def __iter__(self) -> Iterator[_Gen]: ... - def fetchmany(self, size: Optional[int] = ...) -> List[_Gen]: ... + def fetchall(self) -> list[Tuple[Any, ...]]: ... # type: ignore + def fetchall_unbuffered(self) -> Iterator[Tuple[Any, ...]]: ... def scroll(self, value: int, mode: Text = ...) -> None: ... -class SSDictCursor(DictCursorMixin, SSCursor): ... +class DictCursor(DictCursorMixin, Cursor): ... +class SSDictCursor(DictCursorMixin, SSCursor): + def fetchall_unbuffered(self) -> Iterator[dict[Text, Any]]: ... From 7c79a6dda841d5e055f50a619049b31d36c1b462 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 22:01:42 +0300 Subject: [PATCH 03/12] fixening --- stubs/PyMySQL/pymysql/__init__.pyi | 2 +- stubs/PyMySQL/pymysql/connections.pyi | 8 ++++---- stubs/PyMySQL/pymysql/cursors.pyi | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/stubs/PyMySQL/pymysql/__init__.pyi b/stubs/PyMySQL/pymysql/__init__.pyi index a3fc864e63b5..6cfbf75b685d 100644 --- a/stubs/PyMySQL/pymysql/__init__.pyi +++ b/stubs/PyMySQL/pymysql/__init__.pyi @@ -1,5 +1,5 @@ import sys -from typing import Callable, FrozenSet, Tuple +from typing import FrozenSet, Tuple from .connections import Connection as Connection from .constants import FIELD_TYPE as FIELD_TYPE diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index 8c426a004e13..fb9dffa931da 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -1,5 +1,5 @@ from socket import socket as _socket -from typing import Any, AnyStr, Mapping, Optional, Tuple, Type, TypeVar, Generic, overload +from typing import Any, AnyStr, Generic, Mapping, Optional, Tuple, Type, TypeVar, overload from .charset import charset_by_id as charset_by_id, charset_by_name as charset_by_name from .constants import CLIENT as CLIENT, COMMAND as COMMAND, FIELD_TYPE as FIELD_TYPE, SERVER_STATUS as SERVER_STATUS @@ -203,13 +203,13 @@ class MySQLResult: description: Any rows: Any has_next: Any - def __init__(self, connection: Connection) -> None: ... + def __init__(self, connection: Connection[Any]) -> None: ... first_packet: Any def read(self) -> None: ... def init_unbuffered_query(self) -> None: ... class LoadLocalFile: filename: Any - connection: Connection - def __init__(self, filename: Any, connection: Connection) -> None: ... + connection: Connection[Any] + def __init__(self, filename: Any, connection: Connection[Any]) -> None: ... def send_data(self) -> None: ... diff --git a/stubs/PyMySQL/pymysql/cursors.pyi b/stubs/PyMySQL/pymysql/cursors.pyi index 15859c49612e..acca5ad02087 100644 --- a/stubs/PyMySQL/pymysql/cursors.pyi +++ b/stubs/PyMySQL/pymysql/cursors.pyi @@ -6,7 +6,7 @@ _QueryArgs = Union[Tuple[Any, ...], List[Any], Dict[Text, Any], None] _SelfT = TypeVar("_SelfT") class Cursor: - connection: Connection + connection: Connection[Any] description: Tuple[Text, ...] rownumber: int rowcount: int @@ -14,7 +14,7 @@ class Cursor: messages: Any errorhandler: Any lastrowid: int - def __init__(self, connection: Connection) -> None: ... + def __init__(self, connection: Connection[Any]) -> None: ... def __del__(self) -> None: ... def close(self) -> None: ... def setinputsizes(self, *args) -> None: ... @@ -45,6 +45,7 @@ class SSCursor(Cursor): def fetchall_unbuffered(self) -> Iterator[Tuple[Any, ...]]: ... def scroll(self, value: int, mode: Text = ...) -> None: ... -class DictCursor(DictCursorMixin, Cursor): ... -class SSDictCursor(DictCursorMixin, SSCursor): - def fetchall_unbuffered(self) -> Iterator[dict[Text, Any]]: ... +class DictCursor(DictCursorMixin, Cursor): ... # type: ignore + +class SSDictCursor(DictCursorMixin, SSCursor): # type: ignore + def fetchall_unbuffered(self) -> Iterator[dict[Text, Any]]: ... # type: ignore From 9971b4220037e907e8569f2b7ea2e5c1e656d8a3 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 22:11:06 +0300 Subject: [PATCH 04/12] stubtest fixes --- stubs/PyMySQL/@tests/stubtest_allowlist.txt | 1 + stubs/PyMySQL/pymysql/connections.pyi | 2 ++ 2 files changed, 3 insertions(+) diff --git a/stubs/PyMySQL/@tests/stubtest_allowlist.txt b/stubs/PyMySQL/@tests/stubtest_allowlist.txt index 7025f9aee58c..d790527cffdc 100644 --- a/stubs/PyMySQL/@tests/stubtest_allowlist.txt +++ b/stubs/PyMySQL/@tests/stubtest_allowlist.txt @@ -39,6 +39,7 @@ pymysql.converters.escape_time pymysql.converters.escape_timedelta pymysql.converters.escape_unicode pymysql.cursors.Cursor.__del__ +pymysql.cursors.DictCursorMixin.fetch[a-z]* # Intended to change method types of inherited classes pymysql.err.ER pymysql.escape_dict pymysql.escape_sequence diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index fb9dffa931da..96b98f313da3 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -77,6 +77,7 @@ class Connection(Generic[_C]): @overload def __init__( self: Connection[Cursor], # different between overloads + *, host: Optional[str] = ..., user: Optional[Any] = ..., password: str = ..., @@ -113,6 +114,7 @@ class Connection(Generic[_C]): @overload def __init__( self: Connection[_C], # different between overloads + *, host: Optional[str] = ..., user: Optional[Any] = ..., password: str = ..., From aaeda1ed84ae4e6f3804e231e2c44dee0280d010 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 22:15:39 +0300 Subject: [PATCH 05/12] add unrelated ssl arguments to make stubtyst happy --- stubs/PyMySQL/pymysql/connections.pyi | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index 96b98f313da3..b5d81d17df2b 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -74,6 +74,7 @@ class Connection(Generic[_C]): init_command: Any max_allowed_packet: int server_public_key: bytes + # TODO: correct types for ssl args @overload def __init__( self: Connection[Cursor], # different between overloads @@ -94,6 +95,12 @@ class Connection(Generic[_C]): init_command: Optional[Any] = ..., connect_timeout: Optional[int] = ..., ssl: Mapping[Any, Any] | None = ..., + ssl_ca: Any = ..., + ssl_cert: Any = ..., + ssl_disabled: Any = ..., + ssl_key: Any = ..., + ssl_verify_cert: Any = ..., + ssl_verify_identity: Any = ..., read_default_group: Optional[Any] = ..., compress: Optional[Any] = ..., named_pipe: Optional[Any] = ..., @@ -131,6 +138,12 @@ class Connection(Generic[_C]): init_command: Optional[Any] = ..., connect_timeout: Optional[int] = ..., ssl: Mapping[Any, Any] | None = ..., + ssl_ca: Any = ..., + ssl_cert: Any = ..., + ssl_disabled: Any = ..., + ssl_key: Any = ..., + ssl_verify_cert: Any = ..., + ssl_verify_identity: Any = ..., read_default_group: Optional[Any] = ..., compress: Optional[Any] = ..., named_pipe: Optional[Any] = ..., From bf0c294b38e092bff4636c6801474b848c582921 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 22:19:17 +0300 Subject: [PATCH 06/12] stubtest lol --- stubs/PyMySQL/@tests/stubtest_allowlist.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stubs/PyMySQL/@tests/stubtest_allowlist.txt b/stubs/PyMySQL/@tests/stubtest_allowlist.txt index d790527cffdc..4cb4d467c27a 100644 --- a/stubs/PyMySQL/@tests/stubtest_allowlist.txt +++ b/stubs/PyMySQL/@tests/stubtest_allowlist.txt @@ -39,7 +39,9 @@ pymysql.converters.escape_time pymysql.converters.escape_timedelta pymysql.converters.escape_unicode pymysql.cursors.Cursor.__del__ -pymysql.cursors.DictCursorMixin.fetch[a-z]* # Intended to change method types of inherited classes +# DictCursorMixin changes method types of inherited classes, but doesn't contain much at runtime +pymysql.cursors.DictCursorMixin.__iter__ +pymysql.cursors.DictCursorMixin.fetch[a-z]* pymysql.err.ER pymysql.escape_dict pymysql.escape_sequence From 05c5eca2946962c40d34476412ad468bcd6eb379 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 22:20:03 +0300 Subject: [PATCH 07/12] delete a comment that says the obvious --- stubs/PyMySQL/pymysql/connections.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index b5d81d17df2b..6d72e9018ca1 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -74,7 +74,6 @@ class Connection(Generic[_C]): init_command: Any max_allowed_packet: int server_public_key: bytes - # TODO: correct types for ssl args @overload def __init__( self: Connection[Cursor], # different between overloads From 77b078af07d12013841b8d22e04bd5ae279ea655 Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 16 Jun 2021 22:23:33 +0300 Subject: [PATCH 08/12] stubteeeeeeeestt --- stubs/PyMySQL/@tests/stubtest_allowlist.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/stubs/PyMySQL/@tests/stubtest_allowlist.txt b/stubs/PyMySQL/@tests/stubtest_allowlist.txt index 4cb4d467c27a..1bb567319930 100644 --- a/stubs/PyMySQL/@tests/stubtest_allowlist.txt +++ b/stubs/PyMySQL/@tests/stubtest_allowlist.txt @@ -1,5 +1,3 @@ -pymysql.Connect -pymysql.connections.Connection.__init__ pymysql.connections.byte2int pymysql.connections.int2byte pymysql.connections.lenenc_int From faafba48343c635e191c7f8dc04fe4eb725dca02 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 17 Jun 2021 19:40:51 +0300 Subject: [PATCH 09/12] connections.pyi: Optional to new-style union --- stubs/PyMySQL/pymysql/connections.pyi | 98 +++++++++++++-------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index 6d72e9018ca1..bf3d187b5b8f 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -1,5 +1,5 @@ -from socket import socket as _socket -from typing import Any, AnyStr, Generic, Mapping, Optional, Tuple, Type, TypeVar, overload +from socket import socket +from typing import Any, AnyStr, Generic, Mapping, Tuple, Type, TypeVar, overload from .charset import charset_by_id as charset_by_id, charset_by_name as charset_by_name from .constants import CLIENT as CLIENT, COMMAND as COMMAND, FIELD_TYPE as FIELD_TYPE, SERVER_STATUS as SERVER_STATUS @@ -78,21 +78,21 @@ class Connection(Generic[_C]): def __init__( self: Connection[Cursor], # different between overloads *, - host: Optional[str] = ..., - user: Optional[Any] = ..., + host: str | None = ..., + user: Any | None = ..., password: str = ..., - database: Optional[Any] = ..., + database: Any | None = ..., port: int = ..., - unix_socket: Optional[Any] = ..., + unix_socket: Any | None = ..., charset: str = ..., - sql_mode: Optional[Any] = ..., - read_default_file: Optional[Any] = ..., + sql_mode: Any | None = ..., + read_default_file: Any | None = ..., conv=..., - use_unicode: Optional[bool] = ..., + use_unicode: bool | None = ..., client_flag: int = ..., cursorclass: None = ..., # different between overloads - init_command: Optional[Any] = ..., - connect_timeout: Optional[int] = ..., + init_command: Any | None = ..., + connect_timeout: int | None = ..., ssl: Mapping[Any, Any] | None = ..., ssl_ca: Any = ..., ssl_cert: Any = ..., @@ -100,42 +100,42 @@ class Connection(Generic[_C]): ssl_key: Any = ..., ssl_verify_cert: Any = ..., ssl_verify_identity: Any = ..., - read_default_group: Optional[Any] = ..., - compress: Optional[Any] = ..., - named_pipe: Optional[Any] = ..., - autocommit: Optional[bool] = ..., - db: Optional[Any] = ..., - passwd: Optional[Any] = ..., - local_infile: Optional[Any] = ..., + read_default_group: Any | None = ..., + compress: Any | None = ..., + named_pipe: Any | None = ..., + autocommit: bool | None = ..., + db: Any | None = ..., + passwd: Any | None = ..., + local_infile: Any | None = ..., max_allowed_packet: int = ..., - defer_connect: Optional[bool] = ..., + defer_connect: bool | None = ..., auth_plugin_map: Mapping[Any, Any] | None = ..., - read_timeout: Optional[float] = ..., - write_timeout: Optional[float] = ..., - bind_address: Optional[Any] = ..., - binary_prefix: Optional[bool] = ..., - program_name: Optional[Any] = ..., - server_public_key: Optional[bytes] = ..., + read_timeout: float | None = ..., + write_timeout: float | None = ..., + bind_address: Any | None = ..., + binary_prefix: bool | None = ..., + program_name: Any | None = ..., + server_public_key: bytes | None = ..., ): ... @overload def __init__( self: Connection[_C], # different between overloads *, - host: Optional[str] = ..., - user: Optional[Any] = ..., + host: str | None = ..., + user: Any | None = ..., password: str = ..., - database: Optional[Any] = ..., + database: Any | None = ..., port: int = ..., - unix_socket: Optional[Any] = ..., + unix_socket: Any | None = ..., charset: str = ..., - sql_mode: Optional[Any] = ..., - read_default_file: Optional[Any] = ..., + sql_mode: Any | None = ..., + read_default_file: Any | None = ..., conv=..., - use_unicode: Optional[bool] = ..., + use_unicode: bool | None = ..., client_flag: int = ..., cursorclass: Type[_C] = ..., # different between overloads - init_command: Optional[Any] = ..., - connect_timeout: Optional[int] = ..., + init_command: Any | None = ..., + connect_timeout: int | None = ..., ssl: Mapping[Any, Any] | None = ..., ssl_ca: Any = ..., ssl_cert: Any = ..., @@ -143,22 +143,22 @@ class Connection(Generic[_C]): ssl_key: Any = ..., ssl_verify_cert: Any = ..., ssl_verify_identity: Any = ..., - read_default_group: Optional[Any] = ..., - compress: Optional[Any] = ..., - named_pipe: Optional[Any] = ..., - autocommit: Optional[bool] = ..., - db: Optional[Any] = ..., - passwd: Optional[Any] = ..., - local_infile: Optional[Any] = ..., + read_default_group: Any | None = ..., + compress: Any | None = ..., + named_pipe: Any | None = ..., + autocommit: bool | None = ..., + db: Any | None = ..., + passwd: Any | None = ..., + local_infile: Any | None = ..., max_allowed_packet: int = ..., - defer_connect: Optional[bool] = ..., + defer_connect: bool | None = ..., auth_plugin_map: Mapping[Any, Any] | None = ..., - read_timeout: Optional[float] = ..., - write_timeout: Optional[float] = ..., - bind_address: Optional[Any] = ..., - binary_prefix: Optional[bool] = ..., - program_name: Optional[Any] = ..., - server_public_key: Optional[bytes] = ..., + read_timeout: float | None = ..., + write_timeout: float | None = ..., + bind_address: Any | None = ..., + binary_prefix: bool | None = ..., + program_name: Any | None = ..., + server_public_key: bytes | None = ..., ): ... socket: Any rfile: Any @@ -185,7 +185,7 @@ class Connection(Generic[_C]): def kill(self, thread_id): ... def ping(self, reconnect: bool = ...) -> None: ... def set_charset(self, charset) -> None: ... - def connect(self, sock: Optional[_socket] = ...) -> None: ... + def connect(self, sock: socket | None = ...) -> None: ... def write_packet(self, payload) -> None: ... def _read_packet(self, packet_type=...): ... def insert_id(self): ... From 563bdd2867caf136240d05fa5f4d57fa5327b772 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 17 Jun 2021 21:36:03 +0300 Subject: [PATCH 10/12] delete not-ready types --- stubs/PyMySQL/pymysql/connections.pyi | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index bf3d187b5b8f..de119b368666 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -94,12 +94,12 @@ class Connection(Generic[_C]): init_command: Any | None = ..., connect_timeout: int | None = ..., ssl: Mapping[Any, Any] | None = ..., - ssl_ca: Any = ..., - ssl_cert: Any = ..., - ssl_disabled: Any = ..., - ssl_key: Any = ..., - ssl_verify_cert: Any = ..., - ssl_verify_identity: Any = ..., + ssl_ca=..., + ssl_cert=..., + ssl_disabled=..., + ssl_key=..., + ssl_verify_cert=..., + ssl_verify_identity=..., read_default_group: Any | None = ..., compress: Any | None = ..., named_pipe: Any | None = ..., @@ -137,12 +137,12 @@ class Connection(Generic[_C]): init_command: Any | None = ..., connect_timeout: int | None = ..., ssl: Mapping[Any, Any] | None = ..., - ssl_ca: Any = ..., - ssl_cert: Any = ..., - ssl_disabled: Any = ..., - ssl_key: Any = ..., - ssl_verify_cert: Any = ..., - ssl_verify_identity: Any = ..., + ssl_ca=..., + ssl_cert=..., + ssl_disabled=..., + ssl_key=..., + ssl_verify_cert=..., + ssl_verify_identity=..., read_default_group: Any | None = ..., compress: Any | None = ..., named_pipe: Any | None = ..., From d4a95c17536746ecb7304aad5264de3ca414aa52 Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 17 Jun 2021 21:40:15 +0300 Subject: [PATCH 11/12] pyright cleanups --- stubs/PyMySQL/pymysql/connections.pyi | 4 ++-- stubs/PyMySQL/pymysql/cursors.pyi | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/stubs/PyMySQL/pymysql/connections.pyi b/stubs/PyMySQL/pymysql/connections.pyi index de119b368666..f30e0366167a 100644 --- a/stubs/PyMySQL/pymysql/connections.pyi +++ b/stubs/PyMySQL/pymysql/connections.pyi @@ -1,4 +1,4 @@ -from socket import socket +from socket import socket as _socket from typing import Any, AnyStr, Generic, Mapping, Tuple, Type, TypeVar, overload from .charset import charset_by_id as charset_by_id, charset_by_name as charset_by_name @@ -185,7 +185,7 @@ class Connection(Generic[_C]): def kill(self, thread_id): ... def ping(self, reconnect: bool = ...) -> None: ... def set_charset(self, charset) -> None: ... - def connect(self, sock: socket | None = ...) -> None: ... + def connect(self, sock: _socket | None = ...) -> None: ... def write_packet(self, payload) -> None: ... def _read_packet(self, packet_type=...): ... def insert_id(self): ... diff --git a/stubs/PyMySQL/pymysql/cursors.pyi b/stubs/PyMySQL/pymysql/cursors.pyi index 9ab5309d545a..7b95e1738da1 100644 --- a/stubs/PyMySQL/pymysql/cursors.pyi +++ b/stubs/PyMySQL/pymysql/cursors.pyi @@ -1,4 +1,4 @@ -from typing import Any, Dict, Iterable, Iterator, List, Optional, Text, Tuple, TypeVar, Union +from typing import Any, Iterable, Iterator, Optional, Text, Tuple, TypeVar from .connections import Connection From be305368c7afa83076d7c95178fb20ffa397feda Mon Sep 17 00:00:00 2001 From: Akuli Date: Thu, 17 Jun 2021 21:47:25 +0300 Subject: [PATCH 12/12] version update: stubs made based on pymysql 1.0.2 --- stubs/PyMySQL/METADATA.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stubs/PyMySQL/METADATA.toml b/stubs/PyMySQL/METADATA.toml index 31f638bf33df..f339dc7fdf26 100644 --- a/stubs/PyMySQL/METADATA.toml +++ b/stubs/PyMySQL/METADATA.toml @@ -1,2 +1,2 @@ -version = "0.1" +version = "1.0" python2 = true