Skip to content

Commit 7c2c8cf

Browse files
committed
WL#15401: Support for type hints in module mysqlx
The connector/Python X DevAP package currently does not support type hints as opposed to its classic counterpart. This worklog adds type hints support for the mysqlx package to methods and class attributes. Change-Id: I19593b53e762cbd3829a4a9a1f98e2490c39ec0a
1 parent 735322d commit 7c2c8cf

36 files changed

+1249
-793
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@ repos:
3636
hooks:
3737
- id: isort
3838
- repo: https://github.com/pre-commit/mirrors-mypy
39-
rev: v0.981
39+
rev: v0.991
4040
hooks:
4141
- id: mypy
4242
additional_dependencies: [
4343
django-stubs,
4444
gssapi==1.8.1,
4545
dnspython==2.1.0,
4646
]
47-
files: lib/mysql
48-
exclude: lib/mysqlx
47+
files: lib
4948
args: [
5049
--disallow-untyped-defs,
5150
--show-error-codes,

CHANGES.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Copyright (c) 2009, 2023, Oracle and/or its affiliates.
88
Full release notes:
99
http://dev.mysql.com/doc/relnotes/connector-python/en/
1010

11+
v8.0.33
12+
=======
13+
14+
- WL#15401: Support for type hints in module mysqlx
15+
1116
v8.0.32
1217
=======
1318

cpydist/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ def finalize_options(self):
220220
install.extra_link_args = self.extra_link_args
221221
install.skip_vendor = self.skip_vendor
222222

223-
self.distribution.package_data = {"mysql.connector": ["py.typed"]}
223+
self.distribution.package_data = {
224+
"mysql.connector": ["py.typed"],
225+
"mysqlx": ["py.typed"],
226+
}
224227
if not cmd_build_ext.skip_vendor:
225228
self._copy_vendor_libraries()
226229

@@ -481,6 +484,7 @@ def _copy_vendor_libraries(self):
481484
"mysql.connector": [
482485
"py.typed",
483486
],
487+
"mysqlx": ["py.typed"],
484488
}
485489

486490

cpydist/data/msi/PY310.wxs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
Source="$(var.BDist310)\mysqlx\result.$(var.PyExt)" DiskId="1"/>
7878
<File Id="mysqlx_statementpy310" Name="statement.$(var.PyExt)"
7979
Source="$(var.BDist310)\mysqlx\statement.$(var.PyExt)" DiskId="1"/>
80+
<File Id="mysqlx_typespy310" Name="types.$(var.PyExt)"
81+
Source="$(var.BDist310)\mysqlx\types.$(var.PyExt)" DiskId="1"/>
82+
<File Id="mysqlx_pytyped310" Name="py.typed"
83+
Source="$(var.BDist310)\mysqlx\py.typed" DiskId="1"/>
8084
</Component>
8185
</DirectoryRef>
8286

cpydist/data/msi/PY311.wxs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
Source="$(var.BDist311)\mysqlx\result.$(var.PyExt)" DiskId="1"/>
7878
<File Id="mysqlx_statementpy311" Name="statement.$(var.PyExt)"
7979
Source="$(var.BDist311)\mysqlx\statement.$(var.PyExt)" DiskId="1"/>
80+
<File Id="mysqlx_typespy311" Name="types.$(var.PyExt)"
81+
Source="$(var.BDist311)\mysqlx\types.$(var.PyExt)" DiskId="1"/>
82+
<File Id="mysqlx_pytyped311" Name="py.typed"
83+
Source="$(var.BDist311)\mysqlx\py.typed" DiskId="1"/>
8084
</Component>
8185
</DirectoryRef>
8286

cpydist/data/msi/PY37.wxs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
Source="$(var.BDist37)\mysqlx\result.$(var.PyExt)" DiskId="1"/>
7878
<File Id="mysqlx_statementpy37" Name="statement.$(var.PyExt)"
7979
Source="$(var.BDist37)\mysqlx\statement.$(var.PyExt)" DiskId="1"/>
80+
<File Id="mysqlx_typespy37" Name="types.$(var.PyExt)"
81+
Source="$(var.BDist37)\mysqlx\types.$(var.PyExt)" DiskId="1"/>
82+
<File Id="mysqlx_pytyped37" Name="py.typed"
83+
Source="$(var.BDist37)\mysqlx\py.typed" DiskId="1"/>
8084
</Component>
8185
</DirectoryRef>
8286

cpydist/data/msi/PY38.wxs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
Source="$(var.BDist38)\mysqlx\result.$(var.PyExt)" DiskId="1"/>
7878
<File Id="mysqlx_statementpy38" Name="statement.$(var.PyExt)"
7979
Source="$(var.BDist38)\mysqlx\statement.$(var.PyExt)" DiskId="1"/>
80+
<File Id="mysqlx_typespy38" Name="types.$(var.PyExt)"
81+
Source="$(var.BDist38)\mysqlx\types.$(var.PyExt)" DiskId="1"/>
82+
<File Id="mysqlx_pytyped38" Name="py.typed"
83+
Source="$(var.BDist38)\mysqlx\py.typed" DiskId="1"/>
8084
</Component>
8185
</DirectoryRef>
8286

cpydist/data/msi/PY39.wxs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777
Source="$(var.BDist39)\mysqlx\result.$(var.PyExt)" DiskId="1"/>
7878
<File Id="mysqlx_statementpy39" Name="statement.$(var.PyExt)"
7979
Source="$(var.BDist39)\mysqlx\statement.$(var.PyExt)" DiskId="1"/>
80+
<File Id="mysqlx_typespy39" Name="types.$(var.PyExt)"
81+
Source="$(var.BDist39)\mysqlx\types.$(var.PyExt)" DiskId="1"/>
82+
<File Id="mysqlx_pytyped39" Name="py.typed"
83+
Source="$(var.BDist39)\mysqlx\py.typed" DiskId="1"/>
8084
</Component>
8185
</DirectoryRef>
8286

lib/mysqlx/authentication.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
import hashlib
3232
import struct
3333

34+
from typing import Optional
35+
3436
from .helpers import hexlify
3537

3638

37-
def xor_string(hash1, hash2, hash_size):
39+
def xor_string(hash1: bytes, hash2: bytes, hash_size: int) -> bytes:
3840
"""Encrypt/Decrypt function used for password encryption in
3941
authentication, using a simple XOR.
4042
@@ -52,19 +54,19 @@ def xor_string(hash1, hash2, hash_size):
5254
class BaseAuthPlugin:
5355
"""Base class for implementing the authentication plugins."""
5456

55-
def __init__(self, username=None, password=None):
56-
self._username = username
57-
self._password = password
57+
def __init__(self, username: Optional[str] = None, password: Optional[str] = None):
58+
self._username: Optional[str] = username
59+
self._password: Optional[str] = password
5860

59-
def name(self):
61+
def name(self) -> str:
6062
"""Returns the plugin name.
6163
6264
Returns:
6365
str: The plugin name.
6466
"""
6567
raise NotImplementedError
6668

67-
def auth_name(self):
69+
def auth_name(self) -> str:
6870
"""Returns the authentication name.
6971
7072
Returns:
@@ -76,27 +78,27 @@ def auth_name(self):
7678
class MySQL41AuthPlugin(BaseAuthPlugin):
7779
"""Class implementing the MySQL Native Password authentication plugin."""
7880

79-
def name(self):
81+
def name(self) -> str:
8082
"""Returns the plugin name.
8183
8284
Returns:
8385
str: The plugin name.
8486
"""
8587
return "MySQL 4.1 Authentication Plugin"
8688

87-
def auth_name(self):
89+
def auth_name(self) -> str:
8890
"""Returns the authentication name.
8991
9092
Returns:
9193
str: The authentication name.
9294
"""
9395
return "MYSQL41"
9496

95-
def auth_data(self, data):
97+
def auth_data(self, data: bytes) -> str:
9698
"""Hashing for MySQL 4.1 authentication.
9799
98100
Args:
99-
data (str): The authentication data.
101+
data (bytes): The authentication data.
100102
101103
Returns:
102104
str: The authentication response.
@@ -117,23 +119,23 @@ def auth_data(self, data):
117119
class PlainAuthPlugin(BaseAuthPlugin):
118120
"""Class implementing the MySQL Plain authentication plugin."""
119121

120-
def name(self):
122+
def name(self) -> str:
121123
"""Returns the plugin name.
122124
123125
Returns:
124126
str: The plugin name.
125127
"""
126128
return "Plain Authentication Plugin"
127129

128-
def auth_name(self):
130+
def auth_name(self) -> str:
129131
"""Returns the authentication name.
130132
131133
Returns:
132134
str: The authentication name.
133135
"""
134136
return "PLAIN"
135137

136-
def auth_data(self):
138+
def auth_data(self) -> str:
137139
"""Returns the authentication data.
138140
139141
Returns:
@@ -145,30 +147,30 @@ def auth_data(self):
145147
class Sha256MemoryAuthPlugin(BaseAuthPlugin):
146148
"""Class implementing the SHA256_MEMORY authentication plugin."""
147149

148-
def name(self):
150+
def name(self) -> str:
149151
"""Returns the plugin name.
150152
151153
Returns:
152154
str: The plugin name.
153155
"""
154156
return "SHA256_MEMORY Authentication Plugin"
155157

156-
def auth_name(self):
158+
def auth_name(self) -> str:
157159
"""Returns the authentication name.
158160
159161
Returns:
160162
str: The authentication name.
161163
"""
162164
return "SHA256_MEMORY"
163165

164-
def auth_data(self, data):
166+
def auth_data(self, data: bytes) -> str:
165167
"""Hashing for SHA256_MEMORY authentication.
166168
167169
The scramble is of the form:
168170
SHA256(SHA256(SHA256(PASSWORD)),NONCE) XOR SHA256(PASSWORD)
169171
170172
Args:
171-
data (str): The authentication data.
173+
data (bytes): The authentication data.
172174
173175
Returns:
174176
str: The authentication response.

lib/mysqlx/charsets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@
3131
"""This module contains the MySQL Server Character Sets."""
3232

3333
# This file was auto-generated.
34+
from typing import List, Optional, Tuple
35+
3436
_GENERATED_ON = "2022-05-09"
3537
_MYSQL_VERSION = (8, 0, 30)
3638

37-
MYSQL_CHARACTER_SETS = [
39+
MYSQL_CHARACTER_SETS: List[Optional[Tuple[str, str, bool]]] = [
3840
# (character set name, collation, default)
3941
None,
4042
("big5", "big5_chinese_ci", True), # 1
@@ -362,7 +364,7 @@
362364
("utf8mb4", "utf8mb4_mn_cyrl_0900_as_cs", False), # 323
363365
]
364366

365-
MYSQL_CHARACTER_SETS_57 = [
367+
MYSQL_CHARACTER_SETS_57: List[Optional[Tuple[str, str, bool]]] = [
366368
# (character set name, collation, default)
367369
None,
368370
("big5", "big5_chinese_ci", True), # 1

0 commit comments

Comments
 (0)