Skip to content

Commit 88362fe

Browse files
authored
[PyMySQL] Add missing stubs (#14335)
1 parent 7a9a294 commit 88362fe

18 files changed

+882
-779
lines changed
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
pymysql.connections.byte2int
2-
pymysql.connections.int2byte
3-
pymysql.connections.pack_int24
4-
pymysql.cursors.Cursor.__del__
51
# DictCursorMixin changes method types of inherited classes, but doesn't contain much at runtime
62
pymysql.cursors.DictCursorMixin.__iter__
73
pymysql.cursors.DictCursorMixin.fetch[a-z]*
8-
pymysql.escape_dict
9-
pymysql.escape_sequence
10-
pymysql.escape_string
11-
pymysql.util

stubs/PyMySQL/METADATA.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
version = "1.1.*"
22
upstream_repository = "https://github.com/PyMySQL/PyMySQL"
3-
partial_stub = true
4-
5-
[tool.stubtest]
6-
ignore_missing_stub = true

stubs/PyMySQL/pymysql/__init__.pyi

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
from typing import Final
1+
from _typeshed import ReadableBuffer
2+
from collections.abc import Iterable
3+
from typing import Final, SupportsBytes, SupportsIndex
24

5+
from . import connections, constants, converters, cursors
36
from .connections import Connection as Connection
47
from .constants import FIELD_TYPE as FIELD_TYPE
5-
from .converters import escape_dict as escape_dict, escape_sequence as escape_sequence, escape_string as escape_string
68
from .err import (
79
DatabaseError as DatabaseError,
810
DataError as DataError,
@@ -27,14 +29,19 @@ from .times import (
2729

2830
VERSION: Final[tuple[str | int, ...]]
2931
VERSION_STRING: Final[str]
32+
version_info: tuple[int, int, int, str, int]
33+
__version__: str
34+
35+
def get_client_info() -> str: ...
36+
def install_as_MySQLdb() -> None: ...
3037

3138
threadsafety: int
3239
apilevel: str
3340
paramstyle: str
3441

3542
class DBAPISet(frozenset[int]):
36-
def __ne__(self, other) -> bool: ...
37-
def __eq__(self, other) -> bool: ...
43+
def __ne__(self, other: object) -> bool: ...
44+
def __eq__(self, other: object) -> bool: ...
3845
def __hash__(self) -> int: ...
3946

4047
STRING: DBAPISet
@@ -46,16 +53,56 @@ TIMESTAMP: DBAPISet
4653
DATETIME: DBAPISet
4754
ROWID: DBAPISet
4855

49-
def Binary(x) -> bytes: ...
50-
def get_client_info() -> str: ...
56+
def Binary(x: Iterable[SupportsIndex] | SupportsIndex | SupportsBytes | ReadableBuffer) -> bytes: ...
57+
def thread_safe() -> bool: ...
5158

52-
__version__: str
53-
version_info: tuple[int, int, int, str, int]
5459
NULL: str
5560

5661
# pymysql/__init__.py says "Connect = connect = Connection = connections.Connection"
5762
Connect = Connection
5863
connect = Connection
5964

60-
def thread_safe() -> bool: ...
61-
def install_as_MySQLdb() -> None: ...
65+
__all__ = [
66+
"BINARY",
67+
"Binary",
68+
"Connect",
69+
"Connection",
70+
"DATE",
71+
"Date",
72+
"Time",
73+
"Timestamp",
74+
"DateFromTicks",
75+
"TimeFromTicks",
76+
"TimestampFromTicks",
77+
"DataError",
78+
"DatabaseError",
79+
"Error",
80+
"FIELD_TYPE",
81+
"IntegrityError",
82+
"InterfaceError",
83+
"InternalError",
84+
"MySQLError",
85+
"NULL",
86+
"NUMBER",
87+
"NotSupportedError",
88+
"DBAPISet",
89+
"OperationalError",
90+
"ProgrammingError",
91+
"ROWID",
92+
"STRING",
93+
"TIME",
94+
"TIMESTAMP",
95+
"Warning",
96+
"apilevel",
97+
"connect",
98+
"connections",
99+
"constants",
100+
"converters",
101+
"cursors",
102+
"get_client_info",
103+
"paramstyle",
104+
"threadsafety",
105+
"version_info",
106+
"install_as_MySQLdb",
107+
"__version__",
108+
]

stubs/PyMySQL/pymysql/connections.pyi

Lines changed: 62 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
from _typeshed import Incomplete
1+
from _typeshed import FileDescriptorOrPath, Incomplete
22
from collections.abc import Mapping
33
from socket import socket as _socket
44
from ssl import _PasswordType
5-
from typing import Any, AnyStr, Generic, TypeVar, overload
6-
from typing_extensions import Self
5+
from typing import AnyStr, Generic, TypeVar, overload
6+
from typing_extensions import Self, deprecated
77

88
from .charset import charset_by_id as charset_by_id, charset_by_name as charset_by_name
99
from .constants import CLIENT as CLIENT, COMMAND as COMMAND, FIELD_TYPE as FIELD_TYPE, SERVER_STATUS as SERVER_STATUS
1010
from .cursors import Cursor
11-
from .util import byte2int as byte2int, int2byte as int2byte
11+
12+
_C = TypeVar("_C", bound=Cursor)
13+
_C2 = TypeVar("_C2", bound=Cursor)
1214

1315
SSL_ENABLED: bool
1416
DEFAULT_USER: str | None
@@ -17,68 +19,30 @@ DEFAULT_CHARSET: str
1719
TEXT_TYPES: set[int]
1820
MAX_PACKET_LEN: int
1921

20-
_C = TypeVar("_C", bound=Cursor)
21-
_C2 = TypeVar("_C2", bound=Cursor)
22-
2322
def dump_packet(data): ...
24-
def pack_int24(n): ...
2523
def _lenenc_int(i: int) -> bytes: ...
2624

27-
class MysqlPacket:
28-
connection: Any
29-
def __init__(self, data, encoding): ...
30-
def get_all_data(self): ...
31-
def read(self, size): ...
32-
def read_all(self): ...
33-
def advance(self, length): ...
34-
def rewind(self, position: int = 0): ...
35-
def get_bytes(self, position, length: int = 1): ...
36-
def read_string(self) -> bytes: ...
37-
def read_uint8(self) -> Any: ...
38-
def read_uint16(self) -> Any: ...
39-
def read_uint24(self) -> Any: ...
40-
def read_uint32(self) -> Any: ...
41-
def read_uint64(self) -> Any: ...
42-
def read_length_encoded_integer(self) -> int: ...
43-
def read_length_coded_string(self) -> bytes: ...
44-
def read_struct(self, fmt: str) -> tuple[Any, ...]: ...
45-
def is_ok_packet(self) -> bool: ...
46-
def is_eof_packet(self) -> bool: ...
47-
def is_auth_switch_request(self) -> bool: ...
48-
def is_extra_auth_data(self) -> bool: ...
49-
def is_resultset_packet(self) -> bool: ...
50-
def is_load_local_packet(self) -> bool: ...
51-
def is_error_packet(self) -> bool: ...
52-
def check_error(self): ...
53-
def raise_for_error(self) -> None: ...
54-
def dump(self): ...
55-
56-
class FieldDescriptorPacket(MysqlPacket):
57-
def __init__(self, data, encoding): ...
58-
def description(self): ...
59-
def get_column_length(self): ...
60-
6125
class Connection(Generic[_C]):
62-
ssl: Any
63-
host: Any
64-
port: Any
65-
user: Any
66-
password: Any
67-
db: Any
68-
unix_socket: Any
26+
ssl: Incomplete
27+
host: Incomplete
28+
port: Incomplete
29+
user: Incomplete
30+
password: Incomplete
31+
db: Incomplete
32+
unix_socket: Incomplete
6933
charset: str
7034
collation: str | None
71-
bind_address: Any
72-
use_unicode: Any
73-
client_flag: Any
74-
cursorclass: Any
75-
connect_timeout: Any
76-
messages: Any
77-
encoders: Any
78-
decoders: Any
79-
host_info: Any
80-
sql_mode: Any
81-
init_command: Any
35+
bind_address: Incomplete
36+
use_unicode: Incomplete
37+
client_flag: Incomplete
38+
cursorclass: Incomplete
39+
connect_timeout: Incomplete
40+
messages: Incomplete
41+
encoders: Incomplete
42+
decoders: Incomplete
43+
host_info: Incomplete
44+
sql_mode: Incomplete
45+
init_command: Incomplete
8246
max_allowed_packet: int
8347
server_public_key: bytes
8448
@overload
@@ -101,7 +65,7 @@ class Connection(Generic[_C]):
10165
cursorclass: None = None, # different between overloads
10266
init_command=None,
10367
connect_timeout: int | None = 10,
104-
ssl: Mapping[Any, Any] | None = None,
68+
ssl: Mapping[Incomplete, Incomplete] | None = None,
10569
ssl_ca=None,
10670
ssl_cert=None,
10771
ssl_disabled=None,
@@ -118,7 +82,7 @@ class Connection(Generic[_C]):
11882
local_infile: Incomplete | None = False,
11983
max_allowed_packet: int = 16777216,
12084
defer_connect: bool | None = False,
121-
auth_plugin_map: Mapping[Any, Any] | None = None,
85+
auth_plugin_map: Mapping[Incomplete, Incomplete] | None = None,
12286
read_timeout: float | None = None,
12387
write_timeout: float | None = None,
12488
bind_address=None,
@@ -147,7 +111,7 @@ class Connection(Generic[_C]):
147111
cursorclass: type[_C] = ..., # different between overloads
148112
init_command=None,
149113
connect_timeout: int | None = 10,
150-
ssl: Mapping[Any, Any] | None = None,
114+
ssl: Mapping[Incomplete, Incomplete] | None = None,
151115
ssl_ca=None,
152116
ssl_cert=None,
153117
ssl_disabled=None,
@@ -163,27 +127,28 @@ class Connection(Generic[_C]):
163127
local_infile: Incomplete | None = False,
164128
max_allowed_packet: int = 16777216,
165129
defer_connect: bool | None = False,
166-
auth_plugin_map: Mapping[Any, Any] | None = None,
130+
auth_plugin_map: Mapping[Incomplete, Incomplete] | None = None,
167131
read_timeout: float | None = None,
168132
write_timeout: float | None = None,
169133
bind_address=None,
170134
binary_prefix: bool | None = False,
171135
program_name=None,
172136
server_public_key: bytes | None = None,
173137
) -> None: ...
174-
socket: Any
175-
rfile: Any
176-
wfile: Any
138+
socket: Incomplete
139+
rfile: Incomplete
140+
wfile: Incomplete
177141
def close(self) -> None: ...
178142
@property
179143
def open(self) -> bool: ...
144+
def __del__(self) -> None: ...
180145
def autocommit(self, value) -> None: ...
181146
def get_autocommit(self) -> bool: ...
182147
def commit(self) -> None: ...
183148
def begin(self) -> None: ...
184149
def rollback(self) -> None: ...
185150
def select_db(self, db) -> None: ...
186-
def escape(self, obj, mapping: Mapping[Any, Any] | None = None): ...
151+
def escape(self, obj, mapping: Mapping[Incomplete, Incomplete] | None = None): ...
187152
def literal(self, obj): ...
188153
def escape_string(self, s: AnyStr) -> AnyStr: ...
189154
@overload
@@ -195,7 +160,9 @@ class Connection(Generic[_C]):
195160
def affected_rows(self): ...
196161
def kill(self, thread_id): ...
197162
def ping(self, reconnect: bool = True) -> None: ...
198-
def set_charset(self, charset) -> None: ...
163+
@deprecated("Method is deprecated. Use set_character_set() instead.")
164+
def set_charset(self, charset: str) -> None: ...
165+
def set_character_set(self, charset: str, collation: str | None = None) -> None: ...
199166
def connect(self, sock: _socket | None = None) -> None: ...
200167
def write_packet(self, payload) -> None: ...
201168
def _read_packet(self, packet_type=...): ...
@@ -208,35 +175,36 @@ class Connection(Generic[_C]):
208175
def show_warnings(self): ...
209176
def __enter__(self) -> Self: ...
210177
def __exit__(self, *exc_info: object) -> None: ...
211-
Warning: Any
212-
Error: Any
213-
InterfaceError: Any
214-
DatabaseError: Any
215-
DataError: Any
216-
OperationalError: Any
217-
IntegrityError: Any
218-
InternalError: Any
219-
ProgrammingError: Any
220-
NotSupportedError: Any
178+
Warning: Incomplete
179+
Error: Incomplete
180+
InterfaceError: Incomplete
181+
DatabaseError: Incomplete
182+
DataError: Incomplete
183+
OperationalError: Incomplete
184+
IntegrityError: Incomplete
185+
InternalError: Incomplete
186+
ProgrammingError: Incomplete
187+
NotSupportedError: Incomplete
221188

222189
class MySQLResult:
223-
connection: Any
224-
affected_rows: Any
225-
insert_id: Any
226-
server_status: Any
227-
warning_count: Any
228-
message: Any
229-
field_count: Any
230-
description: Any
231-
rows: Any
232-
has_next: Any
233-
def __init__(self, connection: Connection[Any]) -> None: ...
234-
first_packet: Any
190+
connection: Incomplete
191+
affected_rows: Incomplete
192+
insert_id: Incomplete
193+
server_status: Incomplete
194+
warning_count: Incomplete
195+
message: Incomplete
196+
field_count: Incomplete
197+
description: Incomplete
198+
rows: Incomplete
199+
has_next: Incomplete
200+
def __init__(self, connection: Connection[Incomplete]) -> None: ...
201+
def __del__(self) -> None: ...
202+
first_packet: Incomplete
235203
def read(self) -> None: ...
236204
def init_unbuffered_query(self) -> None: ...
237205

238206
class LoadLocalFile:
239-
filename: Any
240-
connection: Connection[Any]
241-
def __init__(self, filename: Any, connection: Connection[Any]) -> None: ...
207+
filename: FileDescriptorOrPath
208+
connection: Connection[Incomplete]
209+
def __init__(self, filename: FileDescriptorOrPath, connection: Connection[Incomplete]) -> None: ...
242210
def send_data(self) -> None: ...

0 commit comments

Comments
 (0)