Skip to content

Commit 79a17cb

Browse files
committed
Adjust code to meet typing, linting and styling guidelines
Change-Id: Ic84a61c37159221b4dd0e18bb6a1ef3e2bfa4365
1 parent 586652a commit 79a17cb

File tree

9 files changed

+27
-19
lines changed

9 files changed

+27
-19
lines changed

mysql-connector-python/lib/mysql/connector/_decorating.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
"""Decorators Hub."""
3030

3131
import functools
32-
from typing import TYPE_CHECKING, Any, Callable
3332
import warnings
33+
34+
from typing import TYPE_CHECKING, Any, Callable
35+
3436
from .constants import RefreshOption
3537

3638
if TYPE_CHECKING:

mysql-connector-python/lib/mysql/connector/aio/_decorating.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929
"""Decorators Hub."""
3030

3131
import functools
32-
from typing import TYPE_CHECKING, Any, Callable
3332
import warnings
33+
34+
from typing import TYPE_CHECKING, Any, Callable
35+
3436
from ..constants import RefreshOption
3537

3638
if TYPE_CHECKING:

mysql-connector-python/lib/mysql/connector/aio/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
warn_ciphersuites_deprecated,
100100
warn_tls_version_deprecated,
101101
)
102+
from ._decorating import cmd_refresh_verify_options
102103
from .abstracts import MySQLConnectionAbstract, MySQLCursorAbstract, ServerInfo
103104
from .charsets import charsets
104105
from .cursor import (
@@ -118,7 +119,6 @@
118119
from .logger import logger
119120
from .network import MySQLTcpSocket, MySQLUnixSocket
120121
from .utils import handle_read_write_timeout
121-
from ._decorating import cmd_refresh_verify_options
122122

123123

124124
class MySQLConnection(MySQLConnectionAbstract):

mysql-connector-python/lib/mysql/connector/aio/network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ async def close_connection(self) -> None:
570570
if self._writer.transport is not None:
571571
self._writer.transport.abort()
572572
await self._writer.wait_closed()
573-
except Exception as _:
573+
except Exception as _: # pylint: disable=broad-exception-caught)
574574
# we can ignore issues like ConnectionRefused or ConnectionAborted
575575
# as these instances might popup if the connection was closed due to timeout issues
576576
pass

mysql-connector-python/lib/mysql/connector/connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
)
5858

5959
from . import version
60+
from ._decorating import cmd_refresh_verify_options
6061
from .abstracts import MySQLConnectionAbstract
6162
from .authentication import MySQLAuthenticator, get_auth_plugin
6263
from .constants import (
@@ -121,7 +122,6 @@
121122
warn_ciphersuites_deprecated,
122123
warn_tls_version_deprecated,
123124
)
124-
from ._decorating import cmd_refresh_verify_options
125125

126126
if TYPE_CHECKING:
127127
from .abstracts import CMySQLPrepStmt
@@ -1635,7 +1635,7 @@ def cmd_stmt_execute(
16351635

16361636
def cmd_stmt_close(
16371637
self,
1638-
statement_id: int,
1638+
statement_id: int, # type: ignore[override]
16391639
**kwargs: Any,
16401640
) -> None:
16411641
"""Deallocate a prepared MySQL statement
@@ -1654,7 +1654,7 @@ def cmd_stmt_close(
16541654

16551655
def cmd_stmt_send_long_data(
16561656
self,
1657-
statement_id: int,
1657+
statement_id: int, # type: ignore[override]
16581658
param_id: int,
16591659
data: BinaryIO,
16601660
**kwargs: Any,
@@ -1699,7 +1699,7 @@ def cmd_stmt_send_long_data(
16991699

17001700
def cmd_stmt_reset(
17011701
self,
1702-
statement_id: int,
1702+
statement_id: int, # type: ignore[override]
17031703
**kwargs: Any,
17041704
) -> None:
17051705
"""Reset data for prepared statement sent as long data

mysql-connector-python/lib/mysql/connector/connection_cext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
)
5151

5252
from . import version
53+
from ._decorating import cmd_refresh_verify_options
5354
from .abstracts import CMySQLPrepStmt, MySQLConnectionAbstract
5455
from .constants import (
5556
ClientFlag,
@@ -82,7 +83,6 @@
8283
warn_ciphersuites_deprecated,
8384
warn_tls_version_deprecated,
8485
)
85-
from ._decorating import cmd_refresh_verify_options
8686

8787
HAVE_CMYSQL = False
8888

@@ -671,7 +671,7 @@ def fetch_eof_status(self) -> Optional[CextEofPacketType]:
671671

672672
return None
673673

674-
def cmd_stmt_prepare( # type: ignore[override]
674+
def cmd_stmt_prepare(
675675
self,
676676
statement: bytes,
677677
**kwargs: Any,
@@ -688,7 +688,7 @@ def cmd_stmt_prepare( # type: ignore[override]
688688
raise InterfaceError(str(err)) from err
689689

690690
@with_context_propagation
691-
def cmd_stmt_execute( # type: ignore[override]
691+
def cmd_stmt_execute(
692692
self,
693693
statement_id: CMySQLPrepStmt,
694694
*args: Any,

mysql-connector-python/lib/mysql/connector/network.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _send_pkt(self, sock: socket.socket, address: str, pkt: bytes) -> None:
162162
"""Write packet to the comm channel."""
163163
try:
164164
sock.sendall(pkt)
165-
except (socket.timeout, TimeoutError) as err:
165+
except TimeoutError as err:
166166
raise WriteTimeoutError(errno=3024) from err
167167
except IOError as err:
168168
raise OperationalError(
@@ -241,8 +241,8 @@ def recv(self, sock: socket.socket, address: str) -> bytearray:
241241

242242
# Read the payload, and return packet
243243
return header + self._recv_chunk(sock, size=payload_len)
244-
except (socket.timeout, TimeoutError) as err:
245-
raise ReadTimeoutError(errno=3024, msg=err) from err
244+
except TimeoutError as err:
245+
raise ReadTimeoutError(errno=3024, msg=err.strerror) from err
246246
except IOError as err:
247247
raise OperationalError(
248248
errno=2055, values=(address, _strioerror(err))
@@ -427,7 +427,7 @@ def recv(self, sock: socket.socket, address: str) -> bytearray:
427427
struct.unpack("<I", header[4:7] + b"\x00")[0],
428428
)
429429
self._recv_compressed_pkt(sock, compressed_pll, uncompressed_pll)
430-
except (socket.timeout, TimeoutError) as err:
430+
except TimeoutError as err:
431431
raise ReadTimeoutError(errno=3024) from err
432432
except IOError as err:
433433
raise OperationalError(
@@ -700,7 +700,7 @@ def open_connection(self) -> None:
700700
)
701701
self.sock.settimeout(self._connection_timeout)
702702
self.sock.connect(self.unix_socket)
703-
except (socket.timeout, TimeoutError) as err:
703+
except TimeoutError as err:
704704
raise ConnectionTimeoutError(
705705
errno=2002,
706706
values=(
@@ -795,7 +795,7 @@ def open_connection(self) -> None:
795795
self.sock = socket.socket(self._family, socktype, proto)
796796
self.sock.settimeout(self._connection_timeout)
797797
self.sock.connect(sockaddr)
798-
except (socket.timeout, TimeoutError) as err:
798+
except TimeoutError as err:
799799
raise ConnectionTimeoutError(
800800
errno=2003,
801801
values=(

mysql-connector-python/lib/mysql/connector/optionfiles.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ def read_option_files(**config: Union[str, List[str]]) -> Dict[str, Any]:
7070
)
7171
del config["option_files"]
7272

73-
config_from_file = option_parser.get_groups_as_dict_with_priority(*groups)
74-
config_options: Dict[str, Tuple[str, int]] = {}
73+
config_from_file: Dict[str, Any] = (
74+
option_parser.get_groups_as_dict_with_priority(*groups)
75+
)
76+
config_options: Dict[str, Tuple[str, int, str]] = {}
7577
for group in groups:
7678
try:
7779
for option, value in config_from_file[group].items():

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ skip_glob = [
4646
'mysql-connector-python/lib/mysql/connector/locales/eng',
4747
'mysqlx-connector-python/lib/mysqlx/locales/eng',
4848
'mysqlx-connector-python/lib/mysqlx/protobuf',
49+
'mysqlx-connector-python/lib/mysqlx/tls_ciphers.py',
50+
'mysql-connector-python/lib/mysql/tls_ciphers.py',
4951
'venv/*',
5052
]
5153

0 commit comments

Comments
 (0)